javascript - How does the ElementUI tree control find the parent node through the child nodes?
typecho
typecho 2017-06-26 10:57:25
0
1
1978

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?

typecho
typecho

Following the voice in heart.

reply all(1)
世界只因有你

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)
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template