2
我有用于防爆一个数据集:Angularjs ORDERBY与整数字符串
$scope.friends =
[{name:'John', score:'10'},
{name:'Mary', score:'19'},
{name:'Mike', score:'-21'},
{name:'Adam', score:'-35'},
{name:'Julie', score:'29'}];
}]);
我用这个数据作为ng-repeat
源,
<tr ng-repeat="friend in friends | orderBy:'-score' ">
<td>{{friend.name}}</td>
<td>{{friend.score}}</td>
</tr>
我想将friends
根据score
在descending
排序订购。如下图所示,
Name Score
-------------
Julie 29
Mary 19
John 10
Mike -21
Adam -35
,但我得到的输出,
Name Score
-------------
Julie 29
Mary 19
John 10
Adam -35
Mike -21
这里是一个Demo Plunker
注意 -21和-35是不是在正确的顺序输出,这是因为score
属性值为String
值。如果我将其更改为int
值,则所有按预期工作。如何克服这一点,并请考虑我无法改变score
属性的类型。
这似乎是在角度有效[悬而未决的问题(https://github.com/angular/angular.js/issues/11435)。提到一些建议来解决它。 – oliveromahony