1

I am working on a user profile page and I am trying to pass data from the controller to a template helper. Here's my controller:

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');
}

});

Here's my template helper:

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

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

Can someone offer me some guidance on how to pass data that I defined in the controller in the template helper??

Thanks!!

4

1 回答 1

1

摆脱助手并改用此模式:

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

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

于 2015-03-31T16:01:34.227 回答