前端项目实战叁佰伍拾陆react-admin和material ui-处理形成树状数据结构2

dataProviders.getStyleTree('t_prod_category', 't_prod_style').then((res: any) => {
      console.log(res, "resssssssss")
      let arr: any = []
      let arr1: any = [{
        key: 0,
        title: "品类管理",
      }]
      res && res.map((item: any, index: number) => {
        arr.push({ key: item.id, title: item.category_name, children: [] })
        item.t_prod_style && item.t_prod_style.map((item1: any, index1: any) => {
          if (arr.children) {
            arr[index].children = []
          }
          arr[index].children.push({ key: item1.id, title: item1.style_name })
        })
      })
      console.log(arr, "arr")
      arr1[0].children = arr
      setTreeDataList(arr1)
    })

posted @ 2023-09-02 23:18  前端导师歌谣  阅读(9)  评论(0)    收藏  举报  来源