export function toTree(data) {
const tree = []
const otherObj = {}
data.forEach(item => {
item.children = []
otherObj[item.id] = item
})
data.forEach(item => {
if (item.comment_id) {
otherObj[item.comment_id].children.push(item)
} else {
tree.push(item)
}
})
// 5.返回树状结构
return tree
}
将数组转换为树形结构
最新推荐文章于 2024-06-10 22:52:06 发布