2014-05-15 2 views
1

저는 ArrayController가 있습니다. 특정 키 값을 기반으로 ArrayController의 내용을 그룹화하고 싶습니다.Ember.js : ArrayController의 그룹화/파티셔닝

예를 들어, 내 ArrayController의 개체 인 경우 :

id status name 
----------------------------- 
1 1  some name 
2 1  some other name 
3 2  blah 
4 3  blah again 

은 그 때 나는 status에 의해 그룹에 내용을하고 싶습니다. 나는에 지정된 ItemController의에 의해 포장되는 템플릿에서
App.SomeArrayController = Ember.ArrayController.extend({ 
    itemController: 'some-item',  

    status1: Ember.computed.filterBy('content', 'status', 1), 
    status2: Ember.computed.filterBy('content', 'status', 2), 
    status3: Ember.computed.filterBy('content', 'status', 3) 
}); 

는, 이러한 표시되고 있지만,이 하지 같습니다

이 작업을 수행하려면, 내 ArrayController에서 계산 된 속성을 사용하여 시도 ArrayController :

// item controller used in the ArrayController 
App.SomeItemController = Ember.ObjectController.extend({ 
    anotherKey: function() { 
    return 'hey ' + this.get('name'); 
    }.property('name') 
}); 


<!-- template to display status=1 items --> 
{{#each status1}} 

    // displays the name (as a property from the model) 
    {{this.name}} 

    // nothing displays here 
    // (leading me to believe it is not being wrapped by the item controller) 
    {{this.anotherKey}} 
{{/each}} 

내가 뭘 잘못하고 있니?

답변

1

itemController은 컨트롤러 컬렉션을 반복 할 때만 항목을 래핑합니다.

{{#each item in controller}} 
    {{item.coolItemControllerProperty}} 
{{/each}} 

컨트롤러 내의 모든 수집에는 적용되지 않습니다. 기본 모델/내용을 반복하려고 시도하면 래핑되지 않습니다.

{{#each item in content}} 
    {{item.coolItemControllerProperty}} // undefined 
{{/each}} 

{{#each item in model}} 
    {{item.coolItemControllerProperty}} // undefined 
{{/each}} 

다행히도 이러한 상황에 대해 템플릿에 itemController을 지정할 수 있습니다.

{{#each item in status1 itemController='some-item'}} 
    {{item.coolItemControllerProperty}} 
{{/each}}