【发布时间】:2014-05-15 17:38:57
【问题描述】:
我有一个 ArrayController,我想根据特定键的值对该 ArrayController 的内容进行分组。
例如,如果我的 ArrayController 中的对象是:
id status name
-----------------------------
1 1 some name
2 1 some other name
3 2 blah
4 3 blah again
那我想把内容按status分组。
为此,我尝试在我的 ArrayController 中使用计算属性:
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 中指定的 itemController 包装:
// 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}}
我做错了什么?
【问题讨论】:
标签: javascript ember.js