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

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


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

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

最佳答案

发布/订阅仅填充您的客户集合Channels
您可以将其视为填充本地存储桶的流。您可能有几个订阅,它们填充了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/

10-11 12:42
查看更多