I used the ElementUI tree control and set check-strictly to true. There is no relationship between checking the child nodes and checking the parent node. Now that I have checked one of the child nodes, how should I pass it? Does this child node find its corresponding parent node or root node?
世界只因有你2017-06-26 10:59:25
Implement it yourself.
Get the id of the child node, then traverse the data to find the parent node
// 广度优先遍历
// data 就是ElementUI的Tree组件里那个data
let node = [data]
let ok = false
let result // 包含你说的那个子节点的父节点
while (!ok) {
let item = node.shift()
if (item.id == id) {
result = item
ok = true
} else if (item.children && item.children.length > 0) {
node = node.concat(item.children)
}
}