2015-03-31 84 views
1

我正在用户配置文件页面上工作,我试图将数据从控制器传递给模板助手。这里是我的控制器:铁路路由器/流星 - 如何将数据从控制器传递到模板?

usersDetailController = RouteController.extend({ 
waitOn: function() { 
    Meteor.subscribe('userProfileExtended', this.params._id); 
}, 

data: function(){ 
    console.log('info is ' + this.params._id); 
    var a = Meteor.users.findOne(this.params._id); 
    console.log(a); 
    return Meteor.users.findOne(this.params._id); 
}, 

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

}); 

这里是我的模板帮手:

Template.Users.helpers({ 
user: function() { 

    //define user based on the data context from the route controller 
} 
}); 

有人可以给我如何通过我在模板辅助控制器定义的数据提供一些指导?

谢谢!

+0

您是否尝试过使用会话? Session.set('someValue',this.params.id) – Ethaan 2015-03-31 16:01:10

回答

1

摆脱帮手,用这种模式来代替:

data: function(){ 
    return { 
    user: Meteor.users.findOne(this.params._id) 
    }; 
} 

这样你就可以在你的模板来引用user因为数据上下文将被设置为路由数据函数的结果。

+0

它终于工作!!!!!非常感谢!!!!!!!!!!! – 2015-03-31 16:28:45

相关问题