数据根据某个属性分组
作者:
欧小肥OuO | 来源:发表于
2023-02-06 19:30 被阅读0次 let listObj = {}
let newarr = []
res.samples.forEach((item) => {
if (!listObj[item.projectType]) {
listObj[item.projectType] = {}
listObj[item.projectType]['projectType'] = item.projectType
}
if (!listObj[item.projectType]['children']) {
listObj[item.projectType]['children'] = []
}
listObj[item.projectType]['children'].push({ ...item })
})
for (const key in listObj) {
if (Object.hasOwnProperty.call(listObj, key)) {
const element = listObj[key]
newarr.push(element)
}
}
本文标题:数据根据某个属性分组
本文链接:https://www.haomeiwen.com/subject/yegtkdtx.html
网友评论