SproutCore 集合排序

发布于 2024-12-10 05:50:34 字数 764 浏览 0 评论 0原文

我有一个待办事项列表,并且有与它们关联的标签属性。在视图上,我有一个“按标签排序”按钮。当我按下该按钮时,我希望集合按标签排序。现在什么也没有发生。下面是代码。怎么了?

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弄潮 2024-12-17 05:50:34
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); 
    }
}
sortTodos: function() {
   Todos.store.find(Todos.Todo).sortProperty('tag');
}

should be:

sortTodos: function() {
   this.set('orderBy', 'tag');
}

Now if you add items, you must use addObject and use arrangedObjects not just 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); 
    }
}
箹锭⒈辈孓 2024-12-17 05:50:34

在 todoListController 中,假设您最初已从数据存储加载控制器的内容。

sortTodos: function(){
var query= SC.Query.local('Todos.Todo', {orderBy: 'tag'});
Todos.todoListController.set('content',Todos.store.find(query));
}

In the todoListController, assuming that you have initially loaded controller's content from data store.

sortTodos: function(){
var query= SC.Query.local('Todos.Todo', {orderBy: 'tag'});
Todos.todoListController.set('content',Todos.store.find(query));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文