let beforeData = [
{
id: 6,
tagId: 9,
tagName: '产品常见问题描述',
title: '3如何交易?',
acticleContent: '单签当前多群单签当前多群单签当前多群单签当前多群单签当前多群单签当前多群
',
typeId: 2,
typeSub: 0,
status: 0,
deleteFlag: 0,
addUserid: 1,
updataBy: null,
addTime: '2020-05-26 09:51:19',
updateTime: null,
memo1: null,
memo2: null,
memo3: null
},
{
id: 5,
tagId: 9,
tagName: '产品常见问题描述',
title: '如何交易?',
acticleContent: '单签当前多群单签当前多群单签当前多群单签当前多群单签当前多群单签当前多群
',
typeId: 2,
typeSub: 0,
status: 0,
deleteFlag: 0,
addUserid: 1,
updataBy: null,
addTime: '2020-05-26 09:51:04',
updateTime: null,
memo1: null,
memo2: null,
memo3: null
},
{
id: 4,
tagId: 6,
tagName: '交易常见问题',
title: '2.不知道填什么',
acticleContent: '不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么不知道填什么
',
typeId: 2,
typeSub: 0,
status: 0,
deleteFlag: 0,
addUserid: 1,
updataBy: null,
addTime: '2020-05-26 09:49:22',
updateTime: null,
memo1: null,
memo2: null,
memo3: null
},
{
id: 3,
tagId: 6,
tagName: '交易常见问题',
title: '1.如何进行提现',
acticleContent:
'自定义内容
',
typeId: 2,
typeSub: 0,
status: 0,
deleteFlag: 0,
addUserid: 1,
updataBy: 1,
addTime: '2020-04-30 13:50:43',
updateTime: '2020-04-30 15:32:41',
memo1: '',
memo2: '',
memo3: ''
}
];
let tempArr = [];
let afterData=[]
for (let i = 0; i < beforeData.length; i++) {
if (tempArr.indexOf(beforeData[i].tagId) === -1) {
afterData.push({
tagId: beforeData[i].tagId,
tagName: beforeData[i].tagName,
origin: [beforeData[i]]
});
tempArr.push(beforeData[i].tagId);
} else {
for (let j = 0; j < afterData.length; j++) {
if (afterData[j].tagId == beforeData[i].tagId) {
afterData[j].origin.push(beforeData[i]);
break;
}
}
}
}
console.log(afterData, 888);