ember.js#按属性排序 [英] ember.js #each order by property

查看:99
本文介绍了ember.js#按属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Ember.Object 的数组,它由Handlebars {{#each}} helper显示我想在每次数组更改时对这些对象的属性进行排序。

I have an array of Ember.Objects which is displayed by Handlebars {{#each}} helper which I want to be sorted by an property of those objects everytime the array changes.

所以像这样:

var arr = [
    Ember.Objects.create({
        position:0,
        label:"foo"
    }),
    Ember.Objects.create({
        position:1,
        label:"bar"
    }),
];

和车把

{{#each arr}}
    <div class="label">{{label}}</div>
{{/each}}

所以如果我更新头寸和 bar 对象变成第一个,我希望视图被更新。我可以依赖 {{#each}} Helper属性吗?

So if I update the positions and the bar object becomes first, I want the view to be updated. Can I depend the {{#each}} Helper on an property?

推荐答案

您必须在您的数据上使用 ArrayController 代理,并设置 sortProperties 属性。然后,使用控制器作为每个数据源。

You have to use an ArrayController proxy on your data, and set the sortProperties attribute. Then, use the controller as the each data source.

示例@ http://jsfiddle.net/MikeAski/Epjqp/

使用控制器作为数据源提供了一个安排好的内容。注意不要直接使用控制器的内容,因为它是原始的源数据...

Using the controller as the data source provides an arranged content. Take care not to use directly the controller's content, as it is the raw source data...

这篇关于ember.js#按属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆