gpt4 book ai didi

AngularJS 和 ng-repeat 中的 orderby 带有特殊字符

转载 作者:行者123 更新时间:2023-12-02 08:02:23 25 4
gpt4 key购买 nike

我在排序包含非英语字母表字符(š、č、ž、..)的字符串时遇到问题

这是 fiddle :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);

关于AngularJS 和 ng-repeat 中的 orderby 带有特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20292319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com