本文介绍了如何在Ember.js中对模型进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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}} 
{{NAME}}
{{/ each}}
pre>

仍显示无序列表。

解决方案

由于 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 the SortableMixin (already mentioned in the comment from @ianpetzer), you can set the properties you want to sort on in sortProperties.

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

这篇关于如何在Ember.js中对模型进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:53