【问题标题】:Meteor Subscribe and Publish not returning data流星订阅和发布不返回数据
【发布时间】:2014-10-09 20:25:04
【问题描述】:

我的 Meteor 应用程序中有以下 pub,我的 Iron 路由器中有 sub,但是对于数据功能,我没有得到任何回报,如果我将发布更改为主题而不是公共主题,那很好。但这不可能是正确的,因为相同的发布两次,我收到了关于它的流星消息。不知道我做错了什么。

我想有一组基于url的公共话题

Meteor.publish('topics' , function() {
    return Topics.find({$or:[{userId: this.userId},{collaboratorsIds: this.userId},{inviteeId:this.userId}]});
});


Meteor.publish('publicTopics' , function(permalinkUser,permalink) {
    return Topics.find({$and:[{permalinkUser: this.permalinkUser},{permalink: this.permalink}]});
});

在我的铁路由器中,我有以下内容

this.route('topicPublic', {
        path: 'public/:permalinkUser/:permalink',
        layoutTemplate: 'layoutApp',
        waitOn: function(){
            return [Meteor.subscribe('publicTopics', this.params.permalinkUser,this.params.permalink)]
        },


        data: function(){
            return Topics.findOne({$and:[{permalinkUser: this.params.permalinkUser},{permalink: this.params.permalink}]});

        }
    });

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    您的 publicTopics 发布功能有误。如果将参数传递给函数,则不会在函数内部使用 this.permalinkUser,而只是使用 permalinkUser。在w3schools 上了解有关函数的更多信息。

    Meteor.publish('publicTopics' , function(permalinkUser,permalink) {
      return Topics.find({$and:[{permalinkUser: permalinkUser},{permalink: permalink}]});
    });
    

    在您的主题发布功能中,您使用 this.userId 因为它是 Meteor 对象的属性。

    【讨论】:

    • 是的,我的错误是没有注意我复制了路由器数据函数的返回值。
    【解决方案2】:

    需要删除“this”——我的错误是没有注意我复制了路由器数据函数的返回值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-04
      • 2016-10-29
      • 2015-09-02
      • 2014-06-16
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多