formatSorting(list, name) {
var flag = 0,
data = [];
for (var i = 0; i < list.length; i++) {
var az = '';
for (var j = 0; j < data.length; j++) {
console.log(data[j].listArr, list, 77)
if (data[j].listArr) {
if (data[j].listArr[0][name] == list[i][name]) {
flag = 1;
az = j;
break;
}
}
}
if (flag == 1) {
data[az].listArr.push(list[i]);
flag = 0;
} else if (flag == 0) {
let wdy = new Array();
wdy.push(list[i]);
let pushObj = {
listArr: wdy,
[name]: wdy[0][name] || ''
}
console.log(pushObj, '955555555')
data.push(pushObj);
}
}
return data
},
//调用
let sArr = [{tableName: "神都"
taskExecutorId: 49},{tableName: "神都"
taskExecutorId: 50}]
console.log(this.formatSorting(sArr,'tableName'))
//[{tableName:'神都',
//listArr:[{tableName: "神都",taskExecutorId: 49},{tableName:"神都"
//taskExecutorId: 50}]}]
js判断key重复合并 递归筛选name重复合并
最新推荐文章于 2022-10-09 22:03:03 发布