【问题标题】:Publish a collection multiple times Meteor js多次发布集合 Meteor js
【发布时间】:2018-03-06 21:47:09
【问题描述】:

我有一个集合,我必须将其作为一个整体以及部分发布。现在的挑战是,一旦我作为一个整体发布,它就会覆盖一次只返回 5 个的那个。有限制的发布是为了实现分页,同时发布都进入一个下拉框。如何发布一个集合,以便没有一个集合会覆盖另一个集合?

这是部分发布。设置为 5。

Meteor.publish('userSchools', function (skipCount) {
  check(skipCount, Number);
  user = Meteor.users.findOne({_id:this.userId})
  if(user) {
      if(user.emails[0].verified) {
         return SchoolDb.find({userId: Meteor.userId()}, {limit: 5, skip: skipCount});
      } else {
         throw new Meteor.Error('Not authorized');
         return false;
      }
   }
});

整体发布

Meteor.publish('allvalues', function () {
  user = Meteor.users.findOne({_id:this.userId})
  if(user) {
      if(user.emails[0].verified) {
         return SchoolDb.find({userId: Meteor.userId()});
      } else {
         throw new Meteor.Error('Not authorized');
         return false;
      }
   }
});

【问题讨论】:

    标签: pagination meteor-blaze meteor-publications meteor-collections


    【解决方案1】:

    这就是 Meteor pub-sub 的行为方式。您可以做的是将limitskipcount 放入订阅的集合以及部分订阅的模板中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2015-02-02
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2016-09-12
      • 2015-03-12
      相关资源
      最近更新 更多