我有一个 Ex 的数据集:
$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
这是一个演示 Plunker
请注意-21 和 -35 在输出中的顺序不正确,这是因为该score
属性是一个String
值。如果我将其更改为int
值,那么一切都按预期工作。如何克服这个问题,请考虑我无法更改score
属性的类型。