emberjs arraycontroller没有排序

时间:2014-08-08 19:12:35

标签: ember.js

我已经回顾了很多例子,但我似乎无法对ArrayController进行排序! 我有:(小提琴http://jsfiddle.net/6bphs4h7/1/

<script type="text/x-handlebars" data-template-name="usergroups">
<ul>
  {{#each}}
    <li>{{name}}
  {{/each}}
</ul>
</script>

var App = Ember.Application.create({});

App.UsergroupsRoute = Ember.Route.extend({
  model: function(params) {
    return [ 
        Ember.Object.create({id: 1, name: 'foo'}), 
        Ember.Object.create({id: 2, name: 'bar'}) 
    ];
  }
});

App.UsergroupsGroupsController = Ember.ArrayController.extend({
  sortProperties: ['name'],
  sortAscending: true,
});

App.Router.map(function(){
  this.resource('usergroups', {path: '/'});
});

1 个答案:

答案 0 :(得分:2)

是因为您的控制器与带模型的路线不同吗?

App.UsergroupsController = Ember.ArrayController.extend({
  sortProperties: ['name'],
  sortAscending: true,
});

您的控制器适用于UsergroupsGroups,应该是Usergroups