数据根据某个属性分组

2023-02-06  本文已影响0人  欧小肥OuO
        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)
          }
        }
上一篇 下一篇

猜你喜欢

热点阅读