gpt4 book ai didi

javascript - 发布订阅好像不起作用

转载 作者:行者123 更新时间:2023-12-03 04:39:43 25 4
gpt4 key购买 nike

我是 meteor 新手,我发现最好删除自动发布。所以我尝试发布和订阅一个集合以获得两个不同的值。在我的 meteor 方面我有:

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;
});

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

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

在第二个组件上:

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

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

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

最佳答案

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

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

另请参阅How do I control two subscriptions to display within a single template?

关于javascript - 发布订阅好像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43138129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com