将list转化为treeData
2021-10-02 本文已影响0人
明天_8c66
```
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
}
```