【问题标题】:How can I pass data from a meteor controller to a meteor helper?如何将数据从流星控制器传递给流星助手?
【发布时间】:2015-07-24 01:58:24
【问题描述】:

我正在尝试将数据从控制器传递给助手:

我的控制器:

exampleController = RouteController.extend({

data: function() {

    var a = 13;
    return {
        info: a
    }
},

action: function() {
    this.render('samplePage');
}

});

我的助手:

Sample.helpers({
    console.log(info)
});

但是,我不断收到“未定义”错误。有什么想法吗?

【问题讨论】:

    标签: javascript meteor controller helper


    【解决方案1】:

    设置数据上下文意味着您的this 设置为您的数据上下文。要访问您的数据上下文,您可以在模板和助手中使用thisthis.something

    附带说明,您的辅助方法语法已关闭。根据this,您应该使用

    Template.sometemplate.helpers({
      somehelper: function(){
        console.log(this.a);
      }
    })
    

    【讨论】:

      猜你喜欢
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 2014-08-22
      • 2013-05-22
      • 2018-01-25
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多