tree取id的数组

61 阅读1分钟
findNodeById (id:id值, nodes:数组) {
   for (const node of nodes) {
   //如果相等直接返回
      if (node.id === id) {
         return node;
      }
      //如果有children属性则递归
      if (node.children) {
         const foundNode = this.findNodeById(id, node.children);
         if (foundNode) {
            return foundNode;
         }
      }
   }
   return null;
},
changBusiness(value){
   if(value){
     const foundNode = this.findNodeById(value, ${tree的数组})
     //此时返回的是对象所以需要【函数返回值】
     this.deptOptions = [foundNode]
     }
   },