We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用场景 一维对象数组,保存部门数据,需要根据上下级关系组建一棵目录树
参考 https://segmentfault.com/a/1190000018692367
demo https://jsbin.com/lakucozoru/edit?js,console,output
function toTreeData(data,pid){ function tree(id) { let arr = [] data.filter(item => { return item.pid === id; }).forEach(item => { arr.push({ id: item.id, name: item.name, children: tree(item.id) }) }) return arr } return tree(pid) // 第一级节点的父id,是null或者0,视情况传入 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
使用场景
一维对象数组,保存部门数据,需要根据上下级关系组建一棵目录树
参考
https://segmentfault.com/a/1190000018692367
demo
https://jsbin.com/lakucozoru/edit?js,console,output
The text was updated successfully, but these errors were encountered: