问题描述
App.SomethingRoute = Ember.Route.extend({
model:function()
{
return App.MyData.find();
}
});
它从MyData接收数据。在我的数据中,我有一个名为NAME的字段。我想以NAME的上升顺序从MyData显示数据。
我已经添加了一个控制器(thx。Toran,直观):
code> App.SomethingController = Ember.ArrayController.extend({
sortProperties:['NAME'],
sortAscending:true
});
但我的模板就是这样:
{{#each model}}
pre>
{{NAME}}
{{/ each}}
仍显示无序列表。
解决方案由于
ArrayController
包含SortableMixin
(在@ianpetzer的评论中已经提到),您可以在sortProperties
中设置要排序的属性。App.SomethingController = Ember.ArrayController.extend({
sortProperties:['name'],
sortAscending:true
});
I use a model in Ember.js like this:
App.SomethingRoute = Ember.Route.extend({ model: function() { return App.MyData.find(); } });
It receives data from MyData. In my data i have a field called "NAME". I would like to display data from MyData in ascendant order by NAME.
I've added a controller (thx. Toran, intuitive) like this:
App.SomethingController = Ember.ArrayController.extend({ sortProperties: ['NAME'], sortAscending: true });
But my template that is like this:
{{#each model}} {{NAME}} {{/each}}
Still shows unordered list. How to make it right?
解决方案Since the
ArrayController
includes theSortableMixin
(already mentioned in the comment from @ianpetzer), you can set the properties you want to sort on insortProperties
.App.SomethingController = Ember.ArrayController.extend({ sortProperties: ['name'], sortAscending: true });
这篇关于如何在Ember.js中对模型进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!