Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 流星。订阅/发布问题_Meteor - Fatal编程技术网

Meteor 流星。订阅/发布问题

Meteor 流星。订阅/发布问题,meteor,Meteor,我有个问题。 我正在尝试建立高图表图形。 工作原理: 我要去我的路线('ship.details'),在这里我没有问题。 我的问题是: 归入(发货、快照、全部)不起作用。 My publish.js: Meteor.publish("ships_snapshots", function(user, options) { if(!this.userId) return null; if(this.userId) { console.log('subsribed by

我有个问题。 我正在尝试建立高图表图形。 工作原理: 我要去我的路线('ship.details'),在这里我没有问题。 我的问题是: 归入(发货、快照、全部)不起作用。 My publish.js:

Meteor.publish("ships_snapshots", function(user, options) {
    if(!this.userId) return null;
    if(this.userId) {
        console.log('subsribed by ' + user);
        return ships_snapshots.find({userId: user}, options);
    }
});
Meteor.publish("ships_snapshots_all", function() {
    return ships_snapshots.find({});
})
My subscribe.js(在lib文件夹中):

问题100%出现在我的subscription中,因为如果我安装autopublish,一切都正常。我想我的路由器也有问题

router.js:

Router.route('/ships/details', {
    name: 'ship.details',
    loadingTemplate: 'loading',
    onBeforeAction: function() {
        var shipId = Session.get('currentShipId');
        if(!shipId) {
            Router.go('user.ships');
        } else {
            this.next();
        }
    },
    waitOn: function() {

        if (Meteor.isClient) {
        var getCompare = Meteor.user().profile.wows.compareWith;
        console.log(getCompare);
        var user2 = Meteor.users.findOne({"profile.wows.nickname": getCompare});
        var user2Id = user2._id;
        if (getCompare) {
            var user2 = Meteor.users.findOne({"profile.wows.nickname": getCompare});
            if (user2) {
                var user2Id = user2._id;
            }
        }
        if (getCompare) {
            var handle = Meteor.subscribe('ships_snapshots', Meteor.user()._id) && Meteor.subscribe('ships_snapshots', user2Id) && Meteor.subscribe('userSearchInfo', getCompare);
            Session.set('compareWith', user2);
            console.log('user2 _____');
            console.log(user2);
            return handle
        } else {
            var handle = Meteor.subscribe('ships_snapshots', Meteor.user()._id) && Meteor.subscribe('ships_snapshots', user2Id);
            return handle
        }
    }, data: function() {
            if (handle.ready()) {
            var shipname = this.params.shipName;
            var obj = {};

            var query = ships.findOne(); 
            var shipId = Session.get('currentShipId');
            var result;
            _.each(Meteor.user().profile.wows.ships, function(row) {
                if (row.ship_id === shipId) {
                    result = row;
                }
            });     
            return result;
        }
    }
});
我想我在订阅ship_快照时遇到了问题。这里出了点问题,但我无法解决这个问题

Meteor.publish("ships_snapshots", function(user, options) {
    if(!this.userId) return null;
    if(this.userId) {
        console.log('subsribed by ' + user);
        return ships_snapshots.find({userId: user._id}, options);
    }
});

在发布脚本中,用户真的是id还是用户对象?我把它改成了user.\u id.请检查一下。

你说的“不工作”到底是什么意思?根据你的代码,我假设你总是看到所有的飞船快照

如果路由器中有订阅,则不应在/lib中有订阅。如果你有
Meteor.subscribe('ships_snapshots_all')在/lib中,那么您应该始终看到所有的ship快照(假设您没有在任何地方停止订阅)

此外,您对所有内容的订阅应为:

Meteor.publish("ships_snapshots", function(user, options) {
    if(this.userId) {
        console.log('subsribed by ' + user);
        return ships_snapshots.find({userId: user}, options);
    } else this.ready();
});

当没有用户时,您不希望返回null,您可以将订阅标记为就绪,而不查找任何记录。这不是问题的原因,只是良好的做法。

谢谢您的回复。如您所见,在router.js中,我将user2Id变量(==user2.\u id)传递给publish函数,所以问题不在这里。您的ships\u快照选项始终未定义。这是故意的吗?在我的图形中,我需要获取第二个用户的数据,以便与他比较一些数据,所以我尝试在router.js中进行subsction(但它不起作用),所以我只添加了Meteor.subscribe('ships_snapshots_all')(这是发布所有数据);订阅。js,但它仍然不起作用。谢谢你,米歇尔,你的回答真的对我很有帮助,我发现了主要问题:我没有正确订阅user2信息。
Meteor.publish("ships_snapshots", function(user, options) {
    if(this.userId) {
        console.log('subsribed by ' + user);
        return ships_snapshots.find({userId: user}, options);
    } else this.ready();
});