当前位置: 首页 > Web前端 > vue.js

通过子节点id获取树结构的所有父节点(树数据不包含parentId适用)

时间:2023-03-31 19:37:16 vue.js

//查找所有父节点getAllParentArr(list,id){for(letiinlist){if(list[i.id===id){//查询返回数组对象return[list[i]];}if(list[i].children){letnode=this.getAllParentArr(list[i].children,id);if(node!==undefined){//检查连接父节点returnnode.concat(list[i]);}}}},//调用lettemptArr=[];temptArr=this.getAllParentArr(this.treeNodeList,id);//参数一:树数据,参数二:节点id