Javascript 如何使用EMBER.SORTABLEMIXIN?
我的Javascript 如何使用EMBER.SORTABLEMIXIN?,javascript,sorting,ember.js,handlebars.js,Javascript,Sorting,Ember.js,Handlebars.js,我的FIXTURES包含我想根据ID排序的产品数组 Astcart.Application.FIXTURES=[ { "name" : "astr", "home_products": [ { "id": 3, "name": "Mobiles & Accessories" }, { "id": 2, "name": "Mobil
FIXTURES
包含我想根据ID排序的产品数组
Astcart.Application.FIXTURES=[
{
"name" : "astr",
"home_products": [
{
"id": 3,
"name": "Mobiles & Accessories"
},
{
"id": 2,
"name": "Mobiles & Accessories"
},
{
"id": 1,
"name": "Mobiles & Accessories"
}
]
}
];
我没有得到EMBER.SORTABLEMIXIN的完整示例。我不知道如何在EMBER中进行排序
有人能解释一下如何使用my在ember中进行排序吗?可排序功能由提供。此mixin公开了两个属性:sortAscending
和sortProperties
sortAscending
接受一个布尔值,确定排序是否为递增
- 而
sortProperties
需要一个包含要排序的属性的数组
例如:
控制器
App.IndexController = Ember.Controller.extend(Ember.SortableMixin, {
sortAscending: false,
sortProperties: ['id'],
});
App.IndexController = Ember.Controller.extend(Ember.SortableMixin, {
sortProperties: ['firstName'], // or whatever property you want to initially sort the data by
sortAscending: false, // defaults to "true"
actions: {
sortBy: function(property) {
this.set('sortProperties', [property]);
}
}
});
可以更改这些属性并更新顺序,下面是一个动态排序示例:
控制器
App.IndexController = Ember.Controller.extend(Ember.SortableMixin, {
sortAscending: false,
sortProperties: ['id'],
});
App.IndexController = Ember.Controller.extend(Ember.SortableMixin, {
sortProperties: ['firstName'], // or whatever property you want to initially sort the data by
sortAscending: false, // defaults to "true"
actions: {
sortBy: function(property) {
this.set('sortProperties', [property]);
}
}
});
要访问排列的内容,您应该参考模板中的arrangedContent
,而不是常规的model
属性。像这样:
模板
<script type="text/x-handlebars" data-template-name="index">
<h2>Index Content:</h2>
<table>
<thead>
<th {{action "sortBy" "id"}}>ID</th>
<th {{action "sortBy" "firstName"}}>First Name</th>
<th {{action "sortBy" "lastName"}}>Last Name</th>
</thead>
<tbody>
{{#each arrangedContent as |prop|}}
<tr>
<td>{{prop.id}}</td>
<td>{{prop.firstName}}</td>
<td>{{prop.lastName}}</td>
</tr>
{{/each}}
</tbody>
</table>
</script>
索引内容:
身份证件
名字
姓
{{{#每一个都作为| prop |}安排内容}
{{prop.id}}
{{prop.firstName}
{{prop.lastName}
{{/每个}}
你可以看到它在这里工作
我希望它能有所帮助,因为Ember.SortableMixin将在Ember 2.0(以及ArrayController)中被弃用,建议使用Ember.computed.sort()
,如下所示:你能帮我让我的()这个JSFIDLE工作吗?你想排序什么?在这里,我想根据它的id对产品进行排序。