在 Angular JS 中排序
Order by in Angular JS
我想通过下面的卡片订购
<div ng-app="myApp" ng-controller="Ctrl">
<div ng-repeat="card in myCards | orderBy:'card'">
<businesscard>{{card}}</businesscard>
</div>
</div>
angular.module('myApp', [])
.controller('Ctrl', function($scope) {
$scope.myCards = ['J', 'S', 'A'];
});
我期待的结果是,
一种
杰
S
相反,我得到
杰
小号
A
要按值排序,只需不向 orderBy
提供任何参数(参见 orderBy array item value in Angular ng-repeat):
<div ng-repeat="card in myCards | orderBy">
试试这个
<div ng-repeat="card in myCards | orderBy:'toString()'">
<businesscard>{{card}}</businesscard>
</div>
我想通过下面的卡片订购
<div ng-app="myApp" ng-controller="Ctrl">
<div ng-repeat="card in myCards | orderBy:'card'">
<businesscard>{{card}}</businesscard>
</div>
</div>
angular.module('myApp', [])
.controller('Ctrl', function($scope) {
$scope.myCards = ['J', 'S', 'A'];
});
我期待的结果是, 一种 杰 S
相反,我得到 杰 小号 A
要按值排序,只需不向 orderBy
提供任何参数(参见 orderBy array item value in Angular ng-repeat):
<div ng-repeat="card in myCards | orderBy">
试试这个
<div ng-repeat="card in myCards | orderBy:'toString()'">
<businesscard>{{card}}</businesscard>
</div>