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

标签 javascript meteor meteor-blaze

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

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 });
    }
  });
});

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

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 }}"

但是,问题是,当我加载模式时,this 的上下文似乎发生了变化。在其他情况下,我使用 _.bind 来推送 this 的上下文,但是如何使用 blaze 模板来完成此操作?

最佳答案

我不完全遵循您的语法,并且您没有解释 ion 的内容是什么,但在常规 html 语法中,您可以简单地向动态包含的模板提供数据参数,如下所述在 http://docs.meteor.com/#/full/template_dynamic ,所以在你的情况下(但html语法):

{{> _playerModalView data=this}}

关于javascript - 将 `this.data` 的上下文转移到 Blaze/Meteor 中的其他模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30124795/

相关文章:

javascript - 传单奇怪的 map 大小和平铺行为

javascript - 为什么超链接在我的部分 div 上不起作用?

javascript - 我可以在 javascript 中使用博主条件标签(IF)吗

javascript - 无法使用 Meteor 读取未定义的属性 'bcrypt'

nginx - 使用 Meteor-Up、SSL 和 NGINX 将 Meteor 部署到生产环境

javascript - 如何使用 meteor js 在 android 应用程序中录制来自麦克风的声音

javascript - Meteor - Template.currentData() 没有反应?

javascript - Jquery-UI 可排序列表不能很好地处理 Meteor 模板中的响应式(Reactive)更新

javascript - ReactJS动态创建数据表

javascript - 如何删除#!来自网址