Transferring `this` across templates?


#1

Okay so I am using iron:router and meteoric:ionic together. I have been having a problem with modals (more based around meteor than the frameworks.)

Here is an example route.

Router.map(function () {
  this.route('Players.guild', {
    path: '/players/guild/:guildId',
    template: 'GuildPlayerList',
    waitOn: function () {
      return Meteor.subscribe('guild_players', this.params.guildId);
    },
    data: function () {
      return Players.find({ guildId: this.params.guildId });
    }
  });
});

Then, I have a simple template with a modal.

template(name="GuildPlayerList")
  +ionList
    +each this
      +ionItem avatar=true ion-data-modal="_playerModalView"
        img(src="{{ imageId store='PlayerThumbnails' }}" alt="{{ name }}")
        h2 {{ name }}

template(name="_playerModalView")
  // I want the current player in the +each to push its context of this here
  +ionModal title="{{ name }}"

The problem, however, is it seems that the context of this changes when I load the modal. In other cases, I have used _.bind to push the context of this, but how can this be done with blaze templates?

I was imagining some kind of onRendered function or something


#2

ion-data-modal="_playerModalView" load the template or you’re carrying it elsewhere within the template?

you can try using {{> _playerModalView data }}

data: function () {
  // playerId can be a session or reactiveVar maybe
  return Player.findOne({_id: playerId});
}

_playerModalView It is loaded outside players, when the player is selected just save the _id and the modal data will change


#3

Yeah, I found a workaround by looking into the code of meteor ionic

Template['layout'].events({
  'click #modal-button': function () {
    IonModal.open("_edit", Patients.findOne());
  }
});