流星用户发现在发布中没有返回



我正在尝试返回带有组织ID的流星用户,但我没有得到任何回报。

Meteor.publish('organizationsUsers', function() {
    var user = Meteor.users.findOne(this.userId);
    return Meteor.users.find({organizationId: user.organizationId});
}); 

我的路由器

Meteor.subscribe('organizationsUsers');

和风景

organizationsUsers: function() {
        if (!this.users)
            return;
        return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
    }

在我的模板中,我有

{{#each organizationsUsers}}
{{> userItem}}
{{/each}}

而在 JS 中

organizationsUsers: function() {
        if (!this.users)
            return;
        return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
    },

如果要返回游标,则不应在发布函数中执行多个查询或联接,而应执行以下操作:

// CLIENT
Tracker.autorun(function () {
  if (Meteor.userId()) {
    if (typeof organizationId === 'string') {
      Meteor.subscribe('organizationsUsers', Meteor.user().organizationId);
    } else {
      console.log('error');
      // if necessary, debug why organizationId is not a string
    }
  }
});
// SERVER
Meteor.publish('organizationsUsers', function(organizationId) {
  check(organizationId, String);
  return Meteor.users.find({organizationId: organizationId});
}); 

找出问题,首先我使用了与发布函数相同的代码,该函数在组织中使用userId数组(Meteor Publish和MongoDB)。 蒙戈文档。对于模板,我有以下内容:

organizationsUsers: function() {
    if (!this.users)
         return;
          return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
}

if语句是大小写的问题,这项工作

 organizationsUsers: function() {
    return Meteor.users.find(); // {}, {sort: {createdAt: -1}}

}

最新更新