2015-03-31 85 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

相關問題