render-content中:
this.data = data;
this.root = store.root;
1、根节点下
let _key = this.data.key ;
this.root.childNodes.forEach((item)=> {
if (item.data.key === _key) {
this.$set(item,'expanded',true) ;
}
})
2、子孙节点下
let _node = this.findNode({id: this.data.id, data: this.root.childNodes}) ;
this.$set(_node,'expanded',true) ;
findNode ({ id, data }) {
let _node = data.find( el => el.data.id === id ) ;
if (!_node) {
for (let item of data) {
let _matchNode = this.findNode({ id, data: item.childNodes || [] }) ;
if (_matchNode) {
return _matchNode ;
}
}
}else {
return _node ;
}
}