2

我有一个 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>

我想friendsscore顺序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属性的类型。

4

1 回答 1

2

关于什么

<tr ng-repeat="friend in friends | orderBy:'+-score' ">
  <td>{{friend.name}}</td>
  <td>{{friend.score}}</td>
</tr>

普朗克

于 2015-04-17T13:24:46.407 回答