这个方法怎么自定义children的name
子集的name不确定,怎么自定义children的name
export function flatTree(data, level = 0, index = 0, childrenName = 'children') {
let result = []; let obj
data.forEach(item => {
result.push(obj = {
name: item.name,
path: item.path
})
if (item.children?.length) {
const children = flatTree(item.children, level, index + 1)
if (level > index) {
obj.children = children
} else {
result = result.concat(children)
}
}
})
return result
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)