发布订阅似乎不起作用

编程入门 行业动态 更新时间:2024-10-27 07:16:07
本文介绍了发布订阅似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的流星,我发现最好删除自动发布.因此,我尝试发布和订阅一个集合以获取两个不同的值.在流星方面,我有:

I'm new to meteor and I saw that it's better to remove autopublish. So I try to publish and subscribe a collection to get two different values. In my meteor side I have :

Meteor.publish('channelUser', function(){ var user = Meteor.users.findOne({ '_id':this.userId }); console.log(user); var test = Channels.find({ '_id': {$in : user.profile.channelIds} }); return test; } ); Meteor.publish('channelToJoin', function(){ var user = Meteor.users.findOne({ '_id':this.userId }); console.log(user); var test = Channels.find({'_id': {$nin: user.profile.channelIds}}); console.log(test); return test; });

在客户端的第一个组件中,我有:

And in my client side in a first component I have :

this.channelSub = MeteorObservable.subscribe('channelUser').subscribe(); this.channels = Channels.find({});

在第二个组件上:

Meteor.subscribe("channelToJoin"); this.channels = Channels.find({}).zone();

但是在两个组件的客户端,我都有相同的数据.订阅中是否存在某种冲突?

But on my client side on both of the component, I have the same data. Is there some kind of conflict in the subscribe ?

希望我能清楚地描述我的问题!

I hope I was clear to describe my problem !

推荐答案

Pub/Sub仅填充您的客户端集合 Channels .您可以将其视为填充本地存储桶的流.您可能有多个订阅填充了 Channels 集合的不同文档,但是所有订阅最终都存储在Client上的单个集合中.

Pub/Sub just fills your Client collection Channels. You can see it as a flow filling your local bucket. You may have several subscriptions filling different documents of Channels collection, but all end up in that single collection on the Client.

然后,您必须在客户端上调整查询以获取所需的文档(例如, Channels.find({'_ id':{$ nin:user.profile.channelIds}}); 也可以在客户端上).当然,您在不同的模板中可能会有不同的查询,并且与服务器发布也有所不同.

Then you have to adjust your query on client side to get the documents you need (e.g. Channels.find({'_id': {$nin: user.profile.channelIds}}); on Client as well). Of course you may have different queries in different templates, and different from the server publication as well.

另请参见如何控制两个订阅显示在单个模板中?

更多推荐

发布订阅似乎不起作用

本文发布于:2023-11-13 12:20:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!