如何将数据从流星控制器传递给流星助手?

How can I pass data from a meteor controller to a meteor helper?

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

我的控制器:

exampleController = RouteController.extend({

data: function() {

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

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

});

我的帮手:

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

但是,我一直收到 'undefined' 错误。有什么想法吗?

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

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

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