二维数组排序JS
//二维数组排序
if (!isNull(vm.sfc) && !isNull(vm.operation) && !isNull(vm.resource)) {
$.post("/me-ext/PODDCPluginServlet?method=getAllParams",pData,function(data){
if(data){
//默认可能是字符串格式,此处需要转换一下
data = eval('(' + data + ')');
if(data.RESULT == "SUCCESS"){
var dataList=data.DC_GROUP_LIST;
console.log(dataList);
var aa= sortBySequence(dataList)
console.log(aa);
vm.listParams = aa;
}else {
parentVM.erro_msg = $_error_msg(data.MSG);
}
}
});
}
function sortBySequence(oList) {
var oSortedList = oList.sort(function(a, b) {
var iNumberA = Number(a["sequence"]);
var iNumberB = Number(b["sequence"]);
if (isNaN(iNumberA)) {
return -1;
}
if (isNaN(iNumberB)) {
return 1;
}
return (iNumberA > iNumberB) ? 1 : ((iNumberA < iNumberB) ? -1 : 0);
});
return oSortedList;
}
const upsort=(arr=[],key)=>{
var tmp=JSON.parse(JSON.stringify(arr));
tmp.sort(function(a,b){
a=!isNaN(Number(a[key]))?a[key]:a[key].charCodeAt(0);
b=!isNaN(Number(b[key]))?b[key]:b[key].charCodeAt(0);
return b-a;
});
return tmp;
}
var pData = {
'sfc':vm.sfc,
'operation':vm.operation,
'resource':vm.resource
}
if (!isNull(vm.sfc) && !isNull(vm.operation) && !isNull(vm.resource)) {
$.post("/me-ext/PODDCPluginServlet?method=getAllParams",pData,function(data){
if(data){
//默认可能是字符串格式,此处需要转换一下
data = eval('(' + data + ')');
if(data.RESULT == "SUCCESS"){
var dataList=data.DC_GROUP_LIST;
console.log(dataList);
var aa= upsort(dataList,'description')
console.log(aa);
for(var i = 0;i < aa.length; i++){
aa[i]['bb']=aa[i]['description'].substr(aa[i]['description'].length-1,1);
}
console.log(aa);
aa= upsort(aa,'bb');
vm.listParams = aa;
}else {
parentVM.erro_msg = $_error_msg(data.MSG);
}
}
});
if(currentSuppliers.isEmpty()) {
String[] codeList = keyBarcode.split("/");
if (codeList.length >= 3) {
currentSuppliers = codeList[2].substring(0,3);
}
}
const downsort=(arr=[],key)=>{
var tmp=JSON.parse(JSON.stringify(arr));
tmp.sort(function(a,b){
a=!isNaN(Number(a[key]))?a[key]:a[key].charCodeAt(0);
b=!isNaN(Number(b[key]))?b[key]:b[key].charCodeAt(0);
return b-a;
});
return tmp;
}
const upsort=(arr=[],key)=>{
var tmp=JSON.parse(JSON.stringify(arr));
tmp.sort(function(a,b){
a=!isNaN(Number(a[key]))?a[key]:a[key].charCodeAt(0);
b=!isNaN(Number(b[key]))?b[key]:b[key].charCodeAt(0);
return a-b;
});
return tmp;
}
var dataList=data.DC_GROUP_LIST;
console.log(dataList);
var aa= upsort(dataList,'sequence')