0

私はこのコードを持っています:

   var app = angular.module('app', []);
   app.controller('RadioCtrl', ['$scope', '$http',
     function($scope, $http) {
       $http.jsonp('http://www.filltext.com/?callback=JSON_CALLBACK&rows=5&fname={firstName}&lname={lastName}&id={index}').success(function(data) {
         $scope.people = data;
       })
     }
   ]);
<!DOCTYPE html>
<html ng-app="app">

<head>
  <meta charset="utf-8">
  <title>Radio button</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
</head>

<body>
  <section ng-controller="RadioCtrl">
    <input type="text" ng-model="pepek.fname">
    <br>Ascended
    <input type="radio" ng-model="direction" checked>Descended
    <input type="radio" ng-model="direction" value="reverse">
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>First Name</th>
          <th>Second name</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="person in people| filter:pepek |orderBy:person.id">
          <td>{{person.id}}</td>
          <td>{{person.fname}}</td>
          <td>{{person.lname}}</td>
        </tr>
      </tbody>
    </table>

  </section>
</body>

</html>

[昇順] または [降順] のラジオ ボタンをクリックすると、テーブルが ID 順に並べられます。orderBy:idシンプルまたはorderBy:-idまたはorderBy:person.idまたはorderBy:id:reverseまたはそれらのケースのいずれかを試してもorderBy:id:direction、IDで昇順が並んでいなかった場合でも、常に降順になり、理由がわかりません。前もって感謝します :)

4

2 に答える 2

0

これは、おそらく ID が整数ではなく文字列値として格納されているために発生します。これを試して :

<tr ng-repeat="person in people | orderBy:parseFloat(person.id)">
于 2014-11-14T10:53:01.370 に答える