Tree address, click to get the child level, get all parent names, and splice them to get the full name address

treeFindPath(tree, parentCode) {
      let path = [];
       if (!tree) return [];
       let forFn = function (tree, parentCode) {
         for (const element of tree) {
         // 存放最后返回的内容,返回text集合
         let data = element;
         path.push(data.label);
         if (data.areaCode === parentCode) return path;
         if (data.children) {
             const findChildren = forFn(data.children,parentCode);
             if (findChildren) return findChildren
         }
         path.pop()
         }
       }
         forFn(tree, parentCode);
         return path;
 },

Call
...
let names=this.treeFindPath(this.areaList,this.queryForm.parentCode)
let name=''
// Splice to get the full name address
names.forEach(item=>{ name += item }) this.address = name + this.queryForm.name console.log('address',this.address) ···




Guess you like

Origin blog.csdn.net/qq_26841153/article/details/128459664