Meteor发布 - 订阅用户个人资料

时间:2016-02-09 22:38:56

标签: meteor iron-router

我试图发布用户个人资料。我在publish.js中有以下发布功能:

Meteor.publish("singleProfile", function ( profileId ) {
  check(profileId, String);
  return Meteor.users.find(profileId, { fields: { _id: 1, services: 1, profile: 1 }});
});

这是我在router.js中的路线:

Router.route('/profile/:_id', {
    name:           'profilePage',
    template:       'appProfile',
    onBeforeAction: function() {
      var currentUser = Meteor.userId();
      if(currentUser) {
        this.next();
      } else {
        this.render("signin");
      }
    },
    waitOn: function() {
      this.response = Meteor.subscribe('singleProfile', this.params._id);
      return this.response;
    },
    action: function() {
      this.render('appProfile');
    }
  });

问题是,如何访问appProfile模板中的个人资料详细信息?我是否需要定义模板助手?或者我是否需要修改此代码?

1 个答案:

答案 0 :(得分:1)

您可以使用模板助手:

Template.appProfile.helpers({
    users() {
        return Meteor.users.find();
    }
});

然后在你的模板中:

...
{{#each users}}
    {{profile.myProperty}} <!-- Renders the myProperty field of the profile. -->
{{/each}}
相关问题