2014-09-10 81 views
0

我有一個遊戲,我知道在客戶端每個代碼的ID都能正常工作。例如,如果我是使用下面的與{{game._id}}它正常工作:流星this.params._id未定義基於「:_id?」

Template.gamePage.game = function() { 
    return GameCollection.findOne({current: true}); 
}; 

不過,我想訪問的「提交的出版物;僅限特定的遊戲ID。下面的控制檯日誌返回未定義。

router.js

this.route('gamePage', { 
    path: '/games/:_id?', 
    waitOn: function() { 
     console.log(this.params._id); 
     return [ 
      Meteor.subscribe('randomQuestions', Random.id()), 
      Meteor.subscribe('submissions', this.params._id) 
      ]; 
    } 
    }); 

我懷疑params._id從遊戲拉/:_ ID,但是,我想它,使之保持遊戲/:_ ID?所以我沒有不必要的長地址。

爲什麼我收到未定義params._id任何想法

+0

當你得到this.params._id時,你指向的URL是什麼?undefined? 「我懷疑params._id從遊戲/:_ id」拉到了「的確如此。 – saimeunt 2014-09-10 16:25:21

回答

0

我認爲你有訪問遊戲,例如一個鍵...

Tracker.autorun(function() { 
    Session.set('gameCurrent'); 
}); 

Template.gamePage.helpers({ 
    allGames: function(){ 
    return GameCollection.find({}); 
    }, 
    getCurrentGame:function(){ 
    return Session.get('gameCurrent'); 
    } 

}) 

// with this action you access a the route with the id specified 
Template.gamePage.events({ 
'click button#game' : function(event,template){ 
    Session.set('gameCurrent',this._id); 
    Router.go('editEmail',{_id:this._id}) 
    } 
}) 

請記住,會議只能在客戶端。