2014-04-10 4 views
2

Ember.js를 사용하는 데있어 매우 익숙하며,이 점이 저를 매우 혼란스럽게합니다. ember.js에서 라우팅 할 때 변수 컨트롤러를 사용하는 방법이 있습니까?ember.js의 변수 컨트롤러

나는 조금 설명하려고합니다 :

내가 다른 템플릿에서 다른 컨트롤러에 의해 제어 및 표현 될 필요가 모델의 목록을 가지고있다. 예를 들면 : 나는 경로 items/:item_id를 가지고 있고, 나는 이런 식으로 뭔가를하고 싶은 경우

App.ItemRoute = Ember.Route.extend({ 
    model: function(params) { 
     return items[params.lesson_id]; // edit: should be item_id not lesson_id 
    }, 

    setupController: function(controller, model) { 
     controller.set("model", model); 
    }, 

    renderTemplate: function(controller, model) { 
     this.render(model.template || "item", { 
      controller: model.controller || "ItemController" 
     }); 
    } 
}); 

여기에서 타다 남은 가이드 : http://emberjs.com/guides/routing/rendering-a-template/ 는 컨트롤러 옵션을 this.render을 사용하는 방법을 보여줍니다,하지만 난 (아무것도 통과 할 때

Error while loading route: Error: You passed controller: 'ItemController' into the render method, but no such controller could be found.

이 작업을 수행 할 수있는 더 나은 방법이 있나요 : 심지어 "ItemController"), 나는이 오류가?

답변

2

ItemControllerApp.ItemController 대신 컨트롤러 이름 item을 사용해야합니다.

App.ItemRoute = Ember.Route.extend({ 
    model: function(params) { 
     return items[params.lesson_id]; 
    }, 

    setupController: function(controller, model) { 
     controller.set("model", model); 
    }, 

    renderTemplate: function(controller, model) { 
     this.render(model.template || "item", { 
      controller: model.controller || "item" 
     }); 
    } 
}); 
0

this.controllerFor('item')을 사용하여 특정 컨트롤러를 템플릿에 지정하고 해당 컨트롤러를 정의해야합니다.