【问题标题】:Set Meteor dynamic template Name in ViewModel binding在 ViewModel 绑定中设置 Meteor 动态模板名称
【发布时间】:2015-12-04 13:58:14
【问题描述】:

我有以下模板,它使用 Tempalte.dynamic 助手来呈现动态模板。

    <template name="links">
          <div class="panel-body">
            {{> Template.dynamic template=viewTypeTemplate data=links}}
        </div>
   </template>

如果我使用 viewTypeTemplate 变量作为模板帮助器,这将有效,如下所示。

Template.links.helpers({
   viewTypeTemplate: function () {
        return Session.get('isThumbView') ? 'linkThumbList' : 'linkList';
    }
});

但它不起作用我使用 Meteor Viewmodel 绑定变量而不是模板帮助变量。

Template.links.viewmodel({
    isThumbView: false,
    viewTypeTemplate: function(){
      return this.isThumbView()? 'linkThumbList' : 'linkList';
   }
});

【问题讨论】:

    标签: templates meteor viewmodel


    【解决方案1】:
    Template.links.viewmodel({
        isThumbView: false,
        viewTypeTemplate: function(){
          return this.isThumbView()? 'linkThumbList' : 'linkList';
       }
    },'viewTypeTemplate');
    

    viewTypeTemplate 公开为助手以公开使用。 多个助手

    Template.links.viewmodel({
            isThumbView: false,
            viewTypeTemplate: function(){
              return this.isThumbView()? 'linkThumbList' : 'linkList';
           }
    },['viewTypeTemplate','isThumbView']);
    

    通过Here了解更多信息

    【讨论】:

      猜你喜欢
      • 2010-12-10
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多