级联选择器一般我们存储的只有最后一位,但是回显的时候需要整个目录的节点value值,这时候需要遍历获取父节点的value值
var path = [];
function getPath(tree, id, path) {
for (var i = 0; i < tree.length; i++) {
const node = tree[i];
if (node.value == id) {
path.push(node.value)
return path
} else {
if (node.children && node.children.length) {
if (getPath(node.children, id, path)) {
path.push(node.value)
return path
}
}
}
}
}