【发布时间】:2013-12-15 21:57:02
【问题描述】:
【问题讨论】:
标签: angularjs angularjs-ng-repeat
【问题讨论】:
标签: angularjs angularjs-ng-repeat
在 Angular 1.5.8 中,前面的示例不起作用。 必须应用不同的逻辑。
看起来之前 orderBy 的逻辑被应用到了下一个 orderBy 中,所以为了对名称 ASC 和状态 DESC 进行排序,必须反转名称顺序:
<li class="friend" ng-repeat="friend in friends | orderBy:'name':true | orderBy:'status':true">
【讨论】:
还有另一种选择,您可以在 ng-repeat 和该行中有多个 orderBy 过滤器:
<li class="friend" ng-repeat="friend in friends | orderBy:['status','name']:true">
将是:
<li class="friend" ng-repeat="friend in friends | orderBy:'name':false | orderBy:'status':true">
最后一个orderBy是第一个执行,倒数第二个等等......
这是我的 plunkr:http://plnkr.co/edit/girPFzdi3Zx0yp0ASGVQ?p=preview
【讨论】:
将orderBy 过滤器更改为:
orderBy:['-status','name']
这将按状态降序排列(通过前缀 - 字符),然后是升序名称。目前,您正在传递 true 以反转排序,这导致状态正确(在线优先),但名称要反转(即降序)。
如果你想保持反向布尔值,你可以使用orderBy:['status','-name']:true,但这似乎不如前面所示的那样让status降序清晰。
【讨论】:
<input type="text" ng-model="sort"/><div ng-repeat="review in reviews | orderBy:['-date', sort]">...</div>我做不到