我是Ember的新手,最近遵循了Ember“入门”指南来构建TodoMVC。这是jsbin。
一切正常,但现在我试图通过向TodosController添加todos
来对sortProperties
进行排序:
Todos.TodosController = Ember.ArrayController.extend({
sortProperties: ['title'],
sortAscending: true,
...
});
在模板中,我有这个:
{{#each todo in arrangedContent itemController="todo"}}
...
{{/each}}
基于Ember.SortableMixin documentation,我所做的似乎是合理的,但显然我错过了一些东西。
非常感谢任何帮助!
答案 0 :(得分:1)
感谢stevennunez,我明白了缺少的内容 - 添加以下代码解决了问题:
Todos.TodosIndexController = Ember.ArrayController.extend({
sortProperties: ['title'],
sortAscending: true
});
如果没有定义此控制器,默认情况下,Ember会创建一个"泛型" Ember.ArrayController
用于呈现todos/index
模板。因此,放置在sortProperties
中的TodosController
无效。