Ember - 按多个方向的多个属性排序数组 [英] Ember - sort array by multiple properties in multiple directions

查看:121
本文介绍了Ember - 按多个方向的多个属性排序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过多个属性对Ember Models的集合进行排序,而不是以相同的方向/顺序进行排序。即我需要按照升序顺序中的属性 a 降序中的属性 b 进行排序。有没有办法实现这一点?

I need to sort a collection of Ember Models by multiple properties, and not necessary in the same direction/order. I.e. I need to sort by property a in ascending order and by property b in descending. Is there a way to achieve this?

我尝试设置 sortAscending 属性到数组,但它不工作。
在查看源代码后,似乎这个功能不支持开箱即用(还)。

I tried setting the sortAscending property to a array, but it is not working. After looking into the source it seems that this functionality is not supported out of the box(yet).

推荐答案

在ArrayController中:

In your ArrayController:

sortProperties: ["propA:asc", "propB:desc"]
sortedModel: Ember.computed.sort("model", "sortProperties");

然后在模板的<$中引用 sortedModel c $ c> #each 处理程序。

Then reference sortedModel in your template's #each handler.

这篇关于Ember - 按多个方向的多个属性排序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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