tree 收缩:默认展开根目录,当点击子节点时,展开当前父节点
let currentId
= 3;
function getTree (data
) {
const arr
= [];
data
.map(item
=> {
let obj
= {}
obj
.title
= item
.value
obj
.id
= item
.id
if (item
.id
=== currentId
) {
obj
.selected
= true
obj
.isExpand
= true
}
if (item
.children
) {
obj
.children
= getTree(item
.children
)
const c
= obj
.children
.find(item
=> item
.isExpand
)
if (c
) {
obj
.expand
= true
obj
.isExpand
= true
}
}
arr
.push(obj
)
})
return arr
}
转载请注明原文地址:https://tech.qufami.com/read-14419.html