Browse Source

Pull request #1383: KERNEL-4447 refactor: GB2312排序

Merge in VISUAL/fineui from ~WINDY/fui:master to master

* commit '8bf60eedcaeea9902beb4ce61070dd630b499a84':
  KERNEL-4447 refactor: GB2312排序
es6
windy 5 years ago
parent
commit
772b8d98bc
  1. 48
      src/core/func/function.js
  2. 7
      src/third/sort.gb2312.js

48
src/core/func/function.js

@ -92,6 +92,54 @@ _.extend(BI.Func, {
match: matched, match: matched,
find: find find: find
}; };
},
/**
* 获取按GB2312排序的结果
* @param items
* @param key
* @return {any[]}
*/
getSortedResult: function (items, key) {
var getTextOfItem = BI.isFunction(key) ? key :
function (item, key) {
if (BI.isNotNull(key)) {
return item[key];
}
if (BI.isNotNull(item.text)) {
return item.text;
}
if (BI.isNotNull(item.value)) {
return item.value;
}
return item;
};
return items.sort(function (item1, item2) {
var str1 = getTextOfItem(item1, key);
var str2 = getTextOfItem(item2, key);
if (BI.isNull(str1) && BI.isNull(str2)) {
return 0;
}
if (BI.isNull(str1)) {
return -1;
}
if (BI.isNull(str2)) {
return 1;
}
if (str1 === str2) {
return 0;
}
var len1 = str1.length, len2 = str2.length;
for (var i = 0; i < len1 && i < len2; i++) {
var char1 = str1[i];
var char2 = str2[i];
if (char1 !== char2) {
return BI.CODE_INDEX[char1] - BI.CODE_INDEX[char2]
}
}
return len1 - len2;
});
} }
}); });

7
src/third/sort.gb2312.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save