SproutCore 集合排序
我有一个待办事项列表,并且有与它们关联的标签属性。在视图上,我有一个“按标签排序”按钮。当我按下该按钮时,我希望集合按标签排序。现在什么也没有发生。下面是代码。怎么了?
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}}
I have a list of todos and I have tag property associated with them. On the views, I have a "Sort By Tag" button. When I press that button, I want the collection to be sorted by tag. Nothing is happening now. Below is the code. What's wrong?
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}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是:
现在,如果添加项目,则必须使用
addObject
并使用arrangedObjects
而不仅仅是content
should be:
Now if you add items, you must use
addObject
and usearrangedObjects
not justcontent
在 todoListController 中,假设您最初已从数据存储加载控制器的内容。
In the todoListController, assuming that you have initially loaded controller's content from data store.