2013-12-13 2 views
0

중첩 된 경로에서 오류가 발생하면 throw 된 오류 중 하나가 캐치 될 때까지 상위 경로까지 버블 링됩니다.
오류를 처리 할 수있는 루트 수준은 Application입니다. 그러나 setupController 후크 ApplicationRouteErrorRoute에서 undefined 컨텍스트로 전환 한 후에 트리거됩니다.

코드는, 여기에서 볼 수있다 : http://jsbin.com/ucanam/2563/edit (출력 콘솔에 주어진다) ApplicationRoute에서

제가 ErrorRoute에서 전환 후에 존재하는 초기 모델에 의지. undefined으로 재설정되는 이유는 무엇이며 어떻게 해결해야합니까?오류 하위 구조

편집 :

는 여기에 몇 가지 관련 코드입니다 :

App = Ember.Application.create({}); 

App.Router.map(function() { 
    this.route('articles'); 
}); 

App.ApplicationRoute = Ember.Route.extend({ 
    model: function() { 
    /* model hook is not being called when the error bubbles up (nor afterModel hook) */ 
    /* This is the model expected in Application level */ 
    return [ 
     {"key1": "val1"}, 
     {"key2": "val2"}, 
     {"key3": "val3"} 
    ]; 
    }, 

    setupController: function(controller, model) { 
    /* This hook is called in the usual scenario, when ApplicationRoute first 
     invoked, with same model as defined in the model hook */ 
    /* However, it is also invoked after an error thrown from Articles Route, 
     what happens then is: 
     typeof model == "undefined" */ 
    console.log("SetupController invoked in Application Route:", model);  
    } 
}); 

App.ArticlesRoute = Ember.Route.extend({ 
    model: function() { 
    /* The following throws the error */ 
    Ember.$.ajax("http://"); 
    } 
}); 
+0

링크는 좋지만 게시물 본문에도 관련 코드가 제공되어야합니다. –

답변

0

경로는 절대 '없습니다'모델, 그것은 그냥 경로에 대한 모델을 얻기 위해 사용하는 모델 후크가 있습니다. 오류로 전환 할 때 어떤 모델도 해석되지 않습니다 (오류 인 경우 무한 루프에있게됩니다).

모델이 정적 콘텐츠 인 경우 setupController에서 설정할 수 있습니다.

+0

'setupController'에서 모델을 설정하는 것은 나에게 좋은 해결책이 아닙니다. 모델이 해석 될 때 템플릿에 깜빡임이 생기고 페이지에 내용이 주입 될 것입니다 ('model' 훅의 해상도와 대조적으로, 템플릿 약속이 반환 된 후에 만 ​​렌더링 됨). 또 다른 문제는'afterModel' 훅이 여기서 호출되지 않는다는 것입니다 (첨부 된'jsbin' 예제에서 볼 수 있습니다). 이것은 일반적인 변환과도 다릅니다. – Shany

+0

예, 모델은 동일한 이유로 호출되지 않았습니다. 응용 프로그램 경로에 실제 모델이있을 때 이것이 어디에 문제가되는지 알 수 있지만 오류의 원인이 될 수있는 루트에 논리가있는 경우 어떻게 오류 상태가 될 수 있습니까? – Kingpin2k

+0

machty가 변경되었으므로 설명서가 도움이 될 수 있습니다. https://gist.github.com/machty/5723945 – Kingpin2k