AngularJS和orderby在ng重复与特殊字符

前端之家收集整理的这篇文章主要介绍了AngularJS和orderby在ng重复与特殊字符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法订购包含不在英文字母中的字符的字符串(š,č,ž,..)

这是小提琴:http://fiddle.jshell.net/vhhgh/

这些字母来自斯洛文尼亚文字母.

已经有一段时间了,但我发现其他解决方案: 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);
原文链接:https://www.f2er.com/angularjs/140879.html

猜你在找的Angularjs相关文章