orderBy没有正确过滤数字

时间:2017-02-13 17:41:12

标签: javascript angularjs

我有ng-repeat指令。

<tr data-ng-repeat="list in vm.customer.lists | orderBy: list.id track by $index">
    <td>[[list.name]]</td>
    <td>[[list.locations.length]] Location<span data-ng-cloak data-ng-if="list.locations.length !== 1">s</span></td>
    <td><a data-ng-href="/#/locations/manage/list/edit/[[vm.customer.id]]/[[list.id]]" class="button expand">Manage Locations</a></td>
</tr>

我在vm.customer.lists

中重复了3个列表

我试图通过list.id(1,2,3等)达到最小到最大值

也许我无法通过list订购?

2 个答案:

答案 0 :(得分:1)

应该是,

<tr data-ng-repeat="list in vm.customer.lists | orderBy: 'id' ">

<强>样本

var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.customer = 
      [{
      id: 4,
      name: 'sachin'
      
    }, {
      id: 1,
      name: 'Saurav'
     
    }, {
      id: 3,
      name: 'Dravid'
     
    }, {
      id: 2,
      name: 'Dhoni'
    
    }];
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">  
    <li ng-repeat="list in customer | orderBy: 'id' track by $index">
     {{list.name}}
    </li>
 
</div>

答案 1 :(得分:0)

您在过滤器中缺少引号

GridView {
    model: myModel
    delegate: Text {
        text: object.name(1)
    }
}

&#13;
&#13;
<tr data-ng-repeat="list in customer.lists | orderBy: 'id' track by $index">
&#13;
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.customer = {
    'lists': [{
      id: 4,
      name: 'T',
      locations: []
    }, {
      id: 1,
      name: 'S',
      locations: []
    }, {
      id: 3,
      name: 'R',
      locations: []
    }, {
      id: 2,
      name: 'O',
      locations: []
    }]
  };
});
&#13;
&#13;
&#13;