已经有一段时间了,但我发现其他解决方案:
fiddle
HTML:
<div ng-app='test'> <h2>Users</h2> <div ng-controller="UsersCtrl"> <ul> <li ng-repeat="user in users | localeCompareString"> {{user.surname}} {{user.name}} </li> </ul> </div> </div>
JS:
(function(angular) { 'use strict'; var test=angular.module('test',[]) .controller('UsersCtrl',['$scope',function($scope) { $scope.users = [ {name:'Ben',surname:'Živkovič'},{name:'Ken',surname:'AlGore'},{name:'Erica',surname:'Červ'},{name:'Jane',surname:'Šinigoj'},{name:'Kevin',surname:'Sort'},{name:'Roger',surname:'Willson'},{name:'Kim',surname:'Zorro'} ]; }]).filter('localeCompareString',function(){ return function (items) { //window.console.log(items); items.sort(function (a,b) { return a.surname.localeCompare(b.surname); }); return items; }; }); })(window.angular);