2014-02-27 2 views
2

Ember의 한 경로에서 여러 컨트롤러를 처리하려고합니다. This response는가는 길처럼 보이지만 작동시키기가 어려워지고 있습니다. 결과를 보여주는Ember RSVP 해시가 컨트롤러 내용을 업데이트하지 않습니다.

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
    myData = [1,2,3]; 

    return Em.RSVP.hash({ 
     docs1: myData, 
     docs2: myData 
    });  
    }, 
    setupController: function(controller, model) { 
    controller.set('model', model.docs1);  
    this.controllerFor('documents').set('model', model.docs2); 
    } 
}); 

App.DocumentsController = Ember.ArrayController.extend({ 
    count: function() { 
    return this.get('length'); 
    }.property('@each'), 
}); 

App.IndexController = Em.ArrayController.extend({ 
    count: function() { 
    return this.get('length'); 
    }.property('@each'), 
}); 

와 JSBin을 : 여기에 작동하지 간단한 예입니다

http://jsbin.com/wavigada/1/edit

당신은 인 IndexController 3의 정확한 개수 보고서를 볼 수 있지만, DocumentsController는 아무튼 설정 안해.

아무도 도와 줄 수 있습니까?

+0

귀하가 링크 된 질문은 컨트롤러가 아닌 여러 모델에 대해 설명합니다. 솔직히 하나의 라우트에 대해 여러 컨트롤러가 가능한지 모르겠습니다. – GJK

+0

명시 적 모델을 전달하지 않으면'render' 헬퍼를 사용하는 템플릿에서 Ember.js는 적절하게 모델을 설정할 문서 컨트롤러의 싱글 톤 인스턴스를 반환합니다. 다음은 작동 예제입니다. http://jsbin.com/wavigada/5/edit. (또한 계산 된 속성 뒤에 정리해야하는 몇 개의 후행 쉼표가 있습니다. – Sarus

+0

@Sarus 감사합니다. 귀하의 대답이 내가 찾고있는 것으로 보입니다. – dvreed77

답변

0

당신은 그 내용이 당신이 needs를 통해 IndexControllersetupController에 채우는 documents 컨트롤러를 포함해야합니다

App.IndexController = Em.ArrayController.extend({ 
    needs: ['documents'], 
    count: function() { 
    return this.get('length'); 
    }.property('@each'), 
}); 

그런 다음 당신이 템플릿을 변경해야

<script type="text/x-handlebars" data-template-name="index"> 
    {{count}} 
    {{render 'documents' controllers.documents}} 
</script> 

참고하는 단지 {{render 'documents' controllers.documents}} (질문에서와 같이)은 현재 모델의 documents 속성을 나타내며 존재하지 않습니다.

참조 : http://jsbin.com/wavigada/6/

관련 문제