读取数组树下的某值,并返回其父级下的任何值 vue

 1 // 遍历树 获取对应 id的项中的值
 2     queryTree(tree, value) {
 3       let stark = [];
 4       stark = stark.concat(tree);
 5       while (stark.length) {
 6         const temp = stark.shift();
·      //如果存在children就遍历children深度遍历
7 if (temp.children) { 8 stark = stark.concat(temp.children); 9 }
       //此处的nodeId为数据中的 键值
10 if (temp.nodeId === value) {
11 // 此处可保存 得到的父级数据中的某一项this.form.jointdepartname = temp.nodeName 12 return temp.nodeName; // 此处返回的是我所需的 值 13 } 14 } 15 return ''; 16 },

//用result接收一下
const result = this.queryTree(“此处传入要遍历的数组”,”此处传入指定的数据值“)
//数据的类型来看看吧

  

 

 

 

posted on 2022-11-05 21:13  阿术阿术  阅读(176)  评论(0)    收藏  举报