Meteor 发布覆盖另一个发布 [英] Meteor publish overwrites another publish

查看:38
本文介绍了Meteor 发布覆盖另一个发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种发布方法,如下所示,但是当我订阅客户端搜索页面中的一种发布方法时,它被另一个用于索引页面的方法覆盖.

I have two publish method as below but when I subscribe to one of the publish method in client search page, it is being overwritten with the other one which is meant for index page.

服务器

Meteor.publish("task.index", function() {
  TaskCollection.find()
}

Meteor.publish("task.index.search", function(state) {
  TaskCollection.find({ state: state })
}

客户 - 搜索页面

Meteor.subscribe("task.index.search", state)
// this will always be overwritten with "task.index" published collection

客户 - 索引页

Meteor.subscribe("task.index")

有谁知道如何避免这种情况?

Does anyone know how to avoid this?

推荐答案

欢迎来到 SO!

您看到的覆盖"很可能只是发布/订阅机制的正常 Meteor 行为.

There is a high chance the "override" you see is just the normal Meteor behaviour for Publish/Subscribe mechanism.

您的 task.index" 发布将所有您的 TaskCollection 文档发送给客户端.

Your "task.index" publication sends all your TaskCollection documents to the Client.

因此,同一 TaskCollection 上的任何其他发布都将发送客户已经知道的文档.

Therefore any other publication on that same TaskCollection will send documents that the Client already knows.

然后在您的客户端中,从 TaskCollection 过滤一些文档与您的订阅和发布独立.只需执行你的 TaskCollection.find({ state: state }) 客户端,你就会得到你需要的文件.

Then in your Client, filtering some documents from TaskCollection is independent from your subscription and publication. Just perform your TaskCollection.find({ state: state }) Client side, and you will get the documents you need.

当您仅发布集合的文档子集时,您发布的内容恰好已经是您想要在客户端上显示的过滤文档,因此在您的客户端上您只需显示您知道的所有 Collection 文档.但您必须明白,这是两个不同的步骤:

When you publish only a subset of documents of a Collection, it happens that what you publish is exactly already the filtered documents that you want to display on your Client, therefore on your Client you just display all Collection documents you know of. But you have to understand that these are 2 different steps:

  1. 订阅以向客户发送一些文件.可以设置多个订阅,填充客户端上的相同集合.
  2. 根据(可能是多个)订阅者发送的文档对客户端进行过滤.

另见:发布订阅似乎不起作用

这篇关于Meteor 发布覆盖另一个发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆