【问题标题】:Iron-Router infinite loop onBeforeActionIron-Router 无限循环 onBeforeAction
【发布时间】:2014-11-06 06:50:25
【问题描述】:

从 Meteor 1.0 开始,我在 onBeforeAction 的钩子中有一个无限循环。 (create_game 被永久调用)

onBeforeAction: function(){

if(Meteor.userId()){

  Meteor.call('create_game', this.params._id, 1, function(error, result){
    if (error)
    console.log(error);
    else{
     game_sus = result; 
     Session.set('gamesolo_id', game_sus); 
   }
  });
}
this.next();  

},

waitOn: function() { return Meteor.subscribe('game', Session.get('gamesolo_id))}

无限循环是由于会话变量引起的,如果我删除它,我不会进入循环。我不知道这是由于新版本引起的错误还是什么,但是您知道我该如何解决这个问题吗? 我尝试使用全局变量而不是会话变量,但我不使用这种方式订阅。

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    onBeforeAction 是响应式的,所以如果您在 Meteor.call 回调中设置 Session 变量,那么 onBeforeAction 将再次运行

    您可以使用 onRun 进行此会话设置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 2016-01-31
      相关资源
      最近更新 更多