perf: refs #7793 imrpove sort data method
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
ad76d81908
commit
8f963ab78a
|
@ -139,6 +139,23 @@ function findKeyInOptions() {
|
|||
}
|
||||
|
||||
function setOptions(data) {
|
||||
data = data.sort((a, b) => {
|
||||
const search = lastVal.value?.toString()?.toLowerCase();
|
||||
const aValue = String(a[$props.optionLabel]).toLowerCase();
|
||||
const bValue = String(b[$props.optionLabel]).toLowerCase();
|
||||
|
||||
const aIndex = aValue.indexOf(search);
|
||||
const bIndex = bValue.indexOf(search);
|
||||
|
||||
const aPriority = aIndex === 0 ? 0 : aIndex > 0 ? 1 : 2;
|
||||
const bPriority = bIndex === 0 ? 0 : bIndex > 0 ? 1 : 2;
|
||||
|
||||
if (aPriority !== bPriority) {
|
||||
return aPriority - bPriority;
|
||||
}
|
||||
|
||||
return aValue.localeCompare(bValue);
|
||||
});
|
||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue