简体   繁体   中英

AngularJS - How can i use a filtered array in another filter?

How can I use the filtered array in orderByName in the newFirst filter? Is this possible?

filter = (list | orderByName | newFirst )

I have a list sorted alphabetically and I need to sort again by if it's new or not.

Yes, you can do that. But you have to take care that the second ordering function doesn't override the result of the first one. The easiest way to achieve that, is with the standard orderBy filter of AngularJS with multiple sorting parameters:

Using object properties:

ng-repeat="item in list | orderBy:['name', 'isNew']" 

Using custom comparators:

ng-repeat="item in list | orderBy:[orderByName, newFirst]"

For the second way you need to implement the functions orderByName and newFirst as comparator function (see https://docs.angularjs.org/api/ng/filter/orderBy ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM