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>

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

ここにデモプランカーがあります

出力では -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 に答える