将`this.data`的上下文转移到Blaze / Meteor中的其他模板?

时间:2022-01-20 16:49:29

I have a route gathering some data.

我有一个收集一些数据的路线。

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

然后,我有一个简单的模板

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?

然而,问题是,当我加载模态时,它的上下文似乎发生了变化。在其他情况下,我使用_.bind来推动这个的上下文,但是如何使用blaze模板呢?

1 个解决方案

#1


I don't fully follow your syntax and you don't explain what the ion things are, but in regular html syntax you can simply provide a data argument to the dynamically included template, as described in http://docs.meteor.com/#/full/template_dynamic, so in your case (but html syntax):

我没有完全遵循你的语法,你没有解释离子的含义,但在常规的html语法中,你可以简单地为动态包含的模板提供数据参数,如http://docs.meteor.com中所述。 /#/ full / template_dynamic,所以在你的情况下(但是html语法):

{{> _playerModalView data=this}}

#1


I don't fully follow your syntax and you don't explain what the ion things are, but in regular html syntax you can simply provide a data argument to the dynamically included template, as described in http://docs.meteor.com/#/full/template_dynamic, so in your case (but html syntax):

我没有完全遵循你的语法,你没有解释离子的含义,但在常规的html语法中,你可以简单地为动态包含的模板提供数据参数,如http://docs.meteor.com中所述。 /#/ full / template_dynamic,所以在你的情况下(但是html语法):

{{> _playerModalView data=this}}