【发布时间】:2015-04-14 19:26:37
【问题描述】:
我有一个对象数组,我想根据下拉菜单中的值动态排序。到目前为止,这是我列表中的内容:
ng-repeat="item in filteredItems = (items | filter:searchInput | orderBy:canBeAnything)"
但问题是排序可以是对象的属性或使用函数计算的值。它还应该能够以降序方式排序(可选)。
我知道我可以为 orderBy 后面的 canByAnything 变量使用字符串,传递对象的属性,例如:
“-creationDate” // descending ordering on creation date
“customer.lastname” // ascending ordering on customers last name
我也知道我可以通过如下函数订购:
orderBy:myCalculatedValueFunction // will order in an ascending way based on a calculated value, for example calculating the total price of the object if it was an order or something
但我不知道并且想要实现的是:
- 如何组合它,以便我可以结合对象的属性/属性使用函数进行排序。我的意思是根据用户选择的内容动态地选择其中一个。可以是属性或计算值,可以是降序或升序。
- 如何对计算值进行降序排序
【问题讨论】:
标签: javascript angularjs sorting angularjs-ng-repeat