treeData 就是el-tree :data要绑定的数据 :data=treeData treeOptions.data是接口返回的原始树形结构数据 // 根据关键字过滤后的数据 const treeData = computed(() => { if (!options.searchText) return treeOptions.data; let mhres = filterNodeMethod(options.searchText, treeOptions.data) return mhres }) // 处理搜索后的数据返回树形结构 const filterNodeMethod = (value, arr) => { if (!arr) { return [] } let newarr = []; arr.forEach(element => { if (element.name.indexOf(value) > -1) { const ab = filterNodeMethod(value, element.children); const obj = { ...element, children: ab } newarr.push(obj); } else { if (element.children && element.children.length > 0) { const ab = filterNodeMethod(value, element.children); const obj = { ...element, children: ab }; if (ab && ab.length > 0) { newarr.push(obj); } } } }); return newarr; };
标签:ab,const,element,filterNodeMethod,节点,树型,JS,data,children From: https://www.cnblogs.com/csji/p/17448565.html