gpt4 book ai didi

jquery tablesorter 插件仅以一种方式排序

转载 作者:行者123 更新时间:2023-12-01 04:20:48 27 4
gpt4 key购买 nike

您好,已经编写了 tablesorter 插件来对波兰字符进行排序,但插件仅以一种方式排序 http://jsfiddle.net/Gk43v/这是示例和插件代码

$.tablesorter.addParser({
id: 'polish-chars' ,
type: 'text',
is: function(s)
{
return false;
},
format: function(s)
{
return
s.replace('\u0105'/g, 'a')
.replace('\u0104'/g, 'A')
.replace('\u0118'/g, 'E')
.replace('\u0119'/g, 'e')
.replace('\u0107'/g, 'c')
.replace('\u0106'/g, 'C')
.replace('\u0143'/g, 'N')
.replace('\u0144'/g, 'n')
.replace('Ó'/g, 'O')
.replace('ó'/g, 'o')
.replace('\u0141'/g, 'L')
.replace('\u0142'/g, 'l')
.replace('\u015a'/g, 'S')
.replace('\u015b'/g, 's')
.replace('\u0179'/g, 'Z')
.replace('\u017a'/g, 'z')
.replace('\u017b'/g, 'Z')
.replace('\u017c'/g, 'z')
}
});

编辑:当将此插件与 tablesorter 一起使用时,它没有显示错误 /g,因此它应该看起来像

$.tablesorter.addParser({
id: 'polish-chars',
type: 'text',
is: function(s)
{
return false;
},
format: function(s)
{
return s.replace('ą', 'a')
.replace('Ą', 'A')
.replace('Ę', 'E')
.replace('ę', 'e')
.replace('ć', 'c')
.replace('Ć', 'C')
.replace('Ń', 'N')
.replace('ń', 'n')
.replace('Ó', 'O')
.replace('ó', 'o')
.replace('Ł', 'L')
.replace('ł', 'l')
.replace('Ś', 'S')
.replace('ś', 's')
.replace('Ź', 'Z')
.replace('ź', 'z')
.replace('Ż', 'Z')
.replace('ż', 'z');
}
});

并且按照我想要的方式工作。

最佳答案

使用 /g 替换时,请勿使用引号 ( updated demo ):

$.tablesorter.addParser({
id: 'polish-chars',
type: 'text',
is: function(s) {
return false;
},
format: function(s) {
return s.replace(/\u0105/g, 'a')
.replace(/\u0104/g, 'A')
.replace(/\u0118/g, 'E')
.replace(/\u0119/g, 'e')
.replace(/\u0107/g, 'c')
.replace(/\u0106/g, 'C')
.replace(/\u0143/g, 'N')
.replace(/\u0144/g, 'n')
.replace(/Ó/g, 'O')
.replace(/ó/g, 'o')
.replace(/\u0141/g, 'L')
.replace(/\u0142/g, 'l')
.replace(/\u015a/g, 'S')
.replace(/\u015b/g, 's')
.replace(/\u0179/g, 'Z')
.replace(/\u017a/g, 'z')
.replace(/\u017b/g, 'Z')
.replace(/\u017c/g, 'z');
}
});

或者,你可以尝试我的 tablesorter 分支character equivalents replacementssortLocaleCompare 选项为 true 时。只需将缺少的波兰语字符添加到列表中即可:

$.extend( $.tablesorter.characterEquivalents, {
"a" : "\u0105", // ą
"A" : "\u0104", // Ą
"c" : "\u0107", // ć
"C" : "\u0106", // Ć
"e" : "\u0119", // ę
"E" : "\u0118", // Ę
"l" : "\u0142", // ł
"L" : "\u0141", // Ł
"n" : "\u0144", // ń
"N" : "\u0143", // Ń
"o" : "\u00f3", // ó
"O" : "\u00d3", // Ó
"s" : "\u015b", // ś
"S" : "\u015a", // Ś
"z" : "\u017a\u017c", // źż
"Z" : "\u0179\u017b" // ŹŻ
});

关于jquery tablesorter 插件仅以一种方式排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10798081/

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