小编Rog*_*rer的帖子

根据另一个集合中特定文档的存在,将集合中的文档发布到流星客户端(发布与关系)

我有两个系列

  1. 优惠(相关领域:_ id)
  2. ShareRelations(相关领域:receiverIdofferId)

并且我只想向已登录用户发布已分享给他的优惠.

实际上,我是通过使用辅助数组(visibleOffers)来实现的,我通过循环为每个ShareRelations填充,然后在Offers.find上使用此数组作为$ in选择器.

我想知道这可能是这样做的流星方式,还是我可以用更少和/或更漂亮的代码?

我发布优惠的实际代码如下:

Meteor.publish('offersShared', function () {
  // check if the user is logged in
  if (this.userId) {
    // initialize helper array
    var visibleOffers = [];
    // initialize all shareRelations which the actual user is the receiver
    var shareRelations = ShareRelations.find({receiverId: this.userId});
    // check if such relations exist
    if (shareRelations.count()) {
      // loop trough all shareRelations and push the offerId to the array if the …
Run Code Online (Sandbox Code Playgroud)

publish meteor

8
推荐指数
1
解决办法
1777
查看次数

标签 统计

meteor ×1

publish ×1