// 按照某个字段排序
function objSort(prop) {
return (obj1, obj2) => {
let val1 = obj1[prop];
let val2 = obj2[prop];
if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
val1 = Number(val1);
val2 = Number(val2);
}
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
}
使用方法
zNodes = menuTreeArray.sort(objSort('positionSeqno'));