铁路由器onBeforeAction Meteor v1.0

时间:2014-11-01 15:52:41

标签: meteor iron-router

在Meteor v1.0发布之前,我成功运行了这段代码:

onBeforeAction: function(){

 if(Meteor.userId()){

    Meteor.call('create_game', this.params._id, 1, function(error, result){
    if (error)
     console.log(error);
    else{
      var game_id = result; 
      Session.set('gamesolo_id', game_id);  
    }
   });
  }
},
waitOn: function() { return Meteor.subscribe('game', Session.get('gamesolo_id'))},

自Meteor v1.0起,onBeforeAction钩子中需要this.next()。我试过这个:

onBeforeAction: function(){

 if(Meteor.userId()){

    Meteor.call('create_game', this.params._id, 1, function(error, result){
    if (error)
     console.log(error);
    else{
      var game_id = result; 
      Session.set('gamesolo_id', game_id);  
    }
   });
   this.next();
  }
},
waitOn: function() { return Meteor.subscribe('game', Session.get('gamesolo_id'))},

但事实证明,这是一个循环呼唤永远的方法。 知道怎么解决吗?

1 个答案:

答案 0 :(得分:3)

您现在需要使用onRun而不是onBeforeAction(并且不需要this.next()。)

相关问题