1

重要提示:我目前正在SHARK分支中使用 Meteor 和 Iron-Router

为了抽象问题,假设我有两条路线:

// Home
this.route('home', {
    path: '/',
    layoutTemplate: 'layout',
    action: function() {
        // Performing some animation
    }
});

// User profile
this.route('profile', {
    path: '/profile/:id',
    controller: UserShowRouter
});

UserShowRouter 看起来像这样:

UserShowRouter = RouteController.extend({

before: function() {
    this.subscribe('user', this.params.id).wait();
    this.subscribe('userPlaylists', this.params.id).wait();
},

data: function() {

    var user = Meteor.users.findOne({
            'profile.username': this.params.id
        }),

    var playlistsMade = Playlists.find({
            'user.id': user._id
    });

    return {
        user: user,
        playlistsMade: playlistsMade,
    };

},

action: function() {
    this.render('profile', {
        to: 'rightbarYield'
    });
}

});

Auser有几个playlists。在用户的个人资料页面上,应显示用户数据和他拥有的播放列表。

在 before 钩子中,我订阅了用户和用户拥有的所有播放列表。以下是相应的发布功能:

Meteor.publish('user', function(username) {
    return Meteor.users.find({
        'profile.username': username
     });
});

Meteor.publish('userPlaylists', function(username) {
    return Playlists.find({
        'user.username': username
    });
});

出现以下问题:当我/profile/user第一次访问该页面时,一切都像魅力一样。当我从/profile/user页面更改为/(主页)页面然后返回到/profile/user以下异常时:

Exception from Deps recompute: Error: Member already exists: jzJMYRTYjG9FDqHmT
  at _extend.add (http://localhost:3000/packages/ui.js?b7accb7b6966f638ff085b5d7f310d129aad8c19:1757:17)
  at Object.ObserveSequence.observe.addedAt (http://localhost:3000/packages/ui.js?b7accb7b6966f638ff085b5d7f310d129aad8c19:3572:15)
  at Object.diffFn.addedBefore (http://localhost:3000/packages/observe-sequence.js?c4bfebff26188a6d7bd7b902bf9ad3e3c87a0f77:196:17)
  at http://localhost:3000/packages/minimongo.js?56dbd9be5b85de2aee072a05810b82c155a20d99:2649:42
  at Array.forEach (native)
  at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?13ab483e8a3c795d9991577e65e811cd0b827997:130:11)
  at LocalCollection._diffQueryOrderedChanges (http://localhost:3000/packages/minimongo.js?56dbd9be5b85de2aee072a05810b82c155a20d99:2639:5)
  at diffArray (http://localhost:3000/packages/observe-sequence.js?c4bfebff26188a6d7bd7b902bf9ad3e3c87a0f77:194:3)
  at http://localhost:3000/packages/observe-sequence.js?c4bfebff26188a6d7bd7b902bf9ad3e3c87a0f77:125:11
  at Object._.extend.nonreactive (http://localhost:3000/packages/deps.js?34f4906d0a01d1c2873bed712b3bd039da3c9bab:341:14) 

当我在我的(不是在路由控制器中)开头订阅所有播放列表时,不会出现此问题main.jsMeteor.subscribe('playlists')

但这带来了以下问题:当我不再在profile/user路由上,而是在家庭路由器/上并且现有播放列表之一的数据发生更改(例如,标题已更改)并且在引发异常后重新计算依赖项时:

Exception in queued task: TypeError: Cannot read property 'data' of null
  at Object.ObserveSequence.observe.changed (http://localhost:3000/packages/ui.js?b7accb7b6966f638ff085b5d7f310d129aad8c19:3584:52)
  at Object.cursor.observe.changed (http://localhost:3000/packages/observe-sequence.js?c4bfebff26188a6d7bd7b902bf9ad3e3c87a0f77:137:25)
  at Object.cursor.observeChanges.changed (http://localhost:3000/packages/minimongo.js?56dbd9be5b85de2aee072a05810b82c155a20d99:1096:19)
  at http://localhost:3000/packages/minimongo.js?56dbd9be5b85de2aee072a05810b82c155a20d99:349:15
  at _.extend.runTask (http://localhost:3000/packages/meteor.js?e2f7aa115469a020bb2030038d4f74b320dc9533:558:11)
  at _.extend.flush (http://localhost:3000/packages/meteor.js?e2f7aa115469a020bb2030038d4f74b320dc9533:586:10)
  at _.extend.drain (http://localhost:3000/packages/meteor.js?e2f7aa115469a020bb2030038d4f74b320dc9533:594:12)
  at LocalCollection.update (http://localhost:3000/packages/minimongo.js?56dbd9be5b85de2aee072a05810b82c155a20d99:638:22)
  at Object.self._connection.registerStore.update (http://localhost:3000/packages/mongo-livedata.js?2f66d8591aa3225badaf5a98bfba28287bff3a3d:239:30)
  at Object.store.(anonymous function) [as update] (http://localhost:3000/packages/livedata.js?dab0057c9e7c90bcd874be39d89b9cd54637979b:3583:48)

我不知道问题出在哪里——流星?与铁路由器?与我的订阅或路线?非常感谢任何帮助!谢谢

4

0 回答 0