ember.js #按属性排序 [英] ember.js #each order by property
问题描述
我有一个由 Handlebars {{#each}}
助手显示的 Ember.Object
数组,我想按这些对象的属性对其进行排序每次数组更改时.
I have an array of Ember.Object
s 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
属性.然后,使用控制器作为 each
数据源.
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/
使用控制器作为数据源提供了一个排列好的内容.注意不要直接使用控制器的content
,因为它是原始源数据...
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屋!