2014-11-01 7 views
1

유성 v1.0을 출시하기 전에, 나는 성공이 코드를 실행중인 : 유성 v1.0을하기 때문에, this.next()가 필요하다철 라우터 onBeforeAction 유성 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'))}, 

onBeforeAction 후크. 나는 이것을 시도했다 :

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'))}, 

그러나 이것은 반복적 인 방법으로 호출한다. 문제를 해결하는 방법을 알려주세요.

+0

아마도'if' 문 외부에'this.next()'를 넣으십시오. – Sindis

+0

답장을 보내 주셔서 감사합니다. 그러나 바깥 세상은 아무 것도 변하지 않습니다. 메서드는 영원히 루프이며, 템플릿은 로딩 템플릿과 페이지 템플릿 사이를 계속 전환합니다. – user2409399

답변

3

이제는 onBeforeAction 대신 onRun (그리고 this.next()은 필요하지 않음)을 사용해야합니다.

+0

흥미 롭습니다. 나는 문서에서 onRunAction이라는 후크를 찾지 못했습니다. 어쨌든, 방금 만든 게임에 가입하지 않았기 때문에 저에게 효과적이지 않습니다. waitOn을 사용하여 게임을 구독하기 전에 게임을 만드는 후크가 필요합니다. 기본적으로, onBeforeAction ...하지만 난 그냥이 일과 관련이 없습니다. 다음() – user2409399

+0

죄송합니다, 그것은'onRun' (http://eventedmind.github.io/iron-router/#available-hook-methods)입니다. 답변을 업데이트했습니다. –

관련 문제