我有一个待办事项列表,并且我有与之相关的标签属性。在视图中,我有一个"Sort By Tag“按钮。当我按下那个按钮时,我希望集合按标签排序。现在什么都没发生。下面是代码。怎么了?
In todos.js I have:
Todos.SortingView = SC.TemplateView.extend({
sortBinding: 'Todos.todoListController.sortTodos'
});
and in todoListController, I have:
sortTodos: function() {
Todos.store.find(Todos.Todo).sortProperty('tag');
}
and in the handlebars view I have:
{{#view Todos.SortingView id="stats"}}
{{#view SC.Button classBinding="isActive" target="Todos.todoListController" action="sortTodos"}}
Sort By Tag
{{/view}}
{{/view}}
{{#collection SC.TemplateCollectionView contentBinding="Todos.todoListController" itemClassBinding="content.isDone"}}
{{view Todos.MarkDoneView}} - Tag - {{content.tag}}
{{/collection}}发布于 2011-10-17 23:25:42
sortTodos: function() {
Todos.store.find(Todos.Todo).sortProperty('tag');
}应该是:
sortTodos: function() {
this.set('orderBy', 'tag');
}现在,如果要添加项目,则必须使用addObject和arrangedObjects,而不仅仅是content
createTodo: function(title) {
// var todo = Todos.Todo.create({ title: title });
var todoExists = this.findProperty('title', title).length > 0;
if (!todoExist) {
Todos.store.createRecord(Todos.Todo, { title: title });
// this.pushObject(todo);
}
}发布于 2011-12-24 10:27:29
在todoListController中,假设您最初已经从数据存储中加载了控制器的内容。
sortTodos: function(){
var query= SC.Query.local('Todos.Todo', {orderBy: 'tag'});
Todos.todoListController.set('content',Todos.store.find(query));
}https://stackoverflow.com/questions/7795862
复制相似问题