2019-08-09 ES6数组依据对象属性进行排序

将异步请求获得的数据进行排序

const data=getResponse(yield call(fetchTableData,payload));

const { content }=data;

content.sort(

compare(

"yy1_PurchaseOrder_JEI",

"yy1_PurchaseOrderItem_JEI",

"netDueDate",

)

);

排序函数compare:

export function compare(yy1_PurchaseOrder_JEI,yy1_PurchaseOrderItem_JEI,netDueDate ){

return function(object1,object2) {

const value1=object1[yy1_PurchaseOrder_JEI];

const value2=object2[yy1_PurchaseOrder_JEI];

if(value2< value1){

return 1;

}else if(value2> value1){

return -1;

}else {

const value3=object1[yy1_PurchaseOrderItem_JEI];

const value4=object2[yy1_PurchaseOrderItem_JEI];

if(value4< value3){

return 1;

}else if(value4> value3){

return -1;

}else {

const value5=object1[netDueDate];

const value6=object2[netDueDate];

if(value6< value5){

return 1;

}else if(value6> value5){

return -1;

}else {

return 0;

}

}

}

};

}

你可能感兴趣的:(2019-08-09 ES6数组依据对象属性进行排序)