是否有关于如何使用SortableMixin的信息性文章?

Wil*_*ney 2 ember.js

目前我正在使用JavaScript的本机sort()方法在Ember中进行排序,但实际上我知道我应该使用Ember自己的排序,但不幸的是我完全不知道如何使用它.

我不想浪费人们的时间为我解释(除非你是一个受虐狂),但如果有人知道如何在EmberJS中对一组模型进行排序的精彩文章,那么我们将不胜感激!

目前我有类似下面的内容,我只是在实现使用本机排序再次进行排序,但我在那里停下来因为我想学习正确的方法.

SortOption: Ember.View.extend(
{
    template:   Ember.Handlebars.compile('<li><a href="javascript:void(0);">{{ option }}</a></li>'),
    option:     null,

    click: function()
    {
        var rootView    = this.nearestWithProperty('people');
        var sortBy      = this.get('option');

        var sorted = rootView.get('people').orderBy('formalName');
        rootView.set('people', sorted)
    }
})
Run Code Online (Sandbox Code Playgroud)

buu*_*uda 6

此拉取请求适用于有关SortableMixin的更新文档.

Ember.SortableMixin provides a standard interface for array proxies
to specify a sort order and maintain this sorting when objects are added,
removed, or updated without changing the implicit order of their underlying
content array:
  songs = [ 
   {trackNumber: 4, title: 'Ob-La-Di, Ob-La-Da'},
   {trackNumber: 2, title: 'Back in the U.S.S.R.'},
   {trackNumber: 3, title: 'Glass Onion'},
  ];  

  songsController = Ember.ArrayController.create({
  content: songs,
  sortProperties: ['trackNumber']

 });

 songsController.get('firstObject'); // {trackNumber: 2, title: 'Back in the U.S.S.R.'}
 songsController.addObject({trackNumber: 1, title: 'Dear Prudence'});
 songsController.get('firstObject'); // {trackNumber: 1, title: 'Dear Prudence'}
Run Code Online (Sandbox Code Playgroud)

Sortable Mixin现在包含在0.9.8版本的ArrayController中(我相信).您需要做的就是在控制器上定义sortProperties数组,并arrangedContent在视图中使用该属性.以下是伊万的解释.