AngularJS 排序过滤器标签:orderBy
2018-07-26 17:28 更新
orderBy 是一个排序用的过滤器标签。它可以像 sort 函数那样支持一个排序函数,也可以简单地指定一个属性名进行操作:
<div ng-controller="TestCtrl"> {{ data | orderBy: 'age' }} <br /> {{ data | orderBy: '-age' }} <br /> {{ data | orderBy: '-age' | limitTo: 2 }} <br /> {{ data | orderBy: ['-age', 'name'] }} <br /> </div> <script type="text/javascript"> angular.module('app', [], angular.noop) .controller('TestCtrl', function($scope){ $scope.data = [ {name: 'B', age: 4}, {name: 'A', age: 1}, {name: 'D', age: 3}, {name: 'C', age: 3}, ]; }); angular.bootstrap(document.documentElement, ['app']); </script>
以上内容是否对您有帮助:
更多建议: