mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 03:30:02 +08:00
fix(orderBy): support string predicates containing non-ident characters
The orderBy filter now allows string predicates passed to the orderBy filter to make use property
name predicates containing non-ident strings, such as spaces or percent signs, or non-latin
characters.
This behaviour requires the predicate string to be double-quoted.
In markup, this might look like so:
```html
<div ng-repeat="item in items | orderBy:'\"Tip %\"'">
...
</div>
```
Or in JS:
```js
var sorted = $filter('orderBy')(array, ['"Tip %"', '-"Subtotal $"'], false);
```
Closes #6143
Closes #6144
This commit is contained in:
committed by
Tobias Bosch
parent
93d1c95c61
commit
10d3e1e447
@@ -74,6 +74,12 @@ function orderByFilter($parse){
|
||||
predicate = predicate.substring(1);
|
||||
}
|
||||
get = $parse(predicate);
|
||||
if (get.constant) {
|
||||
var key = get();
|
||||
return reverseComparator(function(a,b) {
|
||||
return compare(a[key], b[key]);
|
||||
}, descending);
|
||||
}
|
||||
}
|
||||
return reverseComparator(function(a,b){
|
||||
return compare(get(a),get(b));
|
||||
|
||||
Reference in New Issue
Block a user