以下是从 A 到 Z 的排序标准:1) 特殊字符 2) 数字 3) 字母
For example:-
$scope.cards = ["815 BRAZOS ST AUSTIN TX 78701","7745 CHEVY CHASE DR AUSTIN TX 78752","701 BRAZOS ST AUSTIN TX 78701","555 ROUND ROCK WEST DR ROUND ROCK TX 78681","400 W 15TH ST AUSTIN TX 78701"]
Expected result after sorting:-
400 W 15TH ST AUSTIN TX 78701
555 ROUND ROCK WEST DR ROUND ROCK TX 78681
701 BRAZOS ST AUSTIN TX 78701
815 BRAZOS ST AUSTIN TX 78701
7745 CHEVY CHASE DR AUSTIN TX 78752
我想使用 AngularorderBy
过滤器来实现这一点。和 JS 自定义排序函数一样,我们有两个参数,通过操作我们可以返回 >0、<0 和 0 来实现自定义排序。
我的尝试
<div ng-controller="MyCtrl">
<ul ng-repeat="card in cards | orderBy:myValueFunction">
<li>{{card}}</li>
</ul>
</div>
JS
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.cards = ["815 BRAZOS ST AUSTIN TX 78701","7745 CHEVY CHASE DR AUSTIN TX 78752","701 BRAZOS ST AUSTIN TX 78701","555 ROUND ROCK WEST DR ROUND ROCK TX 78681","400 W 15TH ST AUSTIN TX 78701"]
$scope.myValueFunction = function(card,card1) {
console.log(card);
console.log(card1);
return card;
}
}
谢谢