美文网首页
将list转化为treeData

将list转化为treeData

作者: 明天_8c66 | 来源:发表于2021-10-02 21:16 被阅读0次

    ```

    export function tranListToTreeData(list, rootValue) {

      const arr = []

      list.forEach(item => {

        if (item.pid === rootValue) {

          const children = tranListToTreeData(list, item.id)

          if (children.length) {

            item.children = children

          }

          arr.push(item)

        }

      })

      return arr

    }

    ```

    相关文章

      网友评论

          本文标题:将list转化为treeData

          本文链接:https://www.haomeiwen.com/subject/jammnltx.html