自定义树形模糊搜索

 1 export const mapTree = (arr, value) => {
 2   let newarr = [];
 3   arr.forEach(element => {
 4     if (element.label.indexOf(value) > -1) {
 5       // 判断条件
 6       newarr.push(element);
 7     } else {
 8       if (element.children && element.children.length > 0) {
 9         let redata = mapTree(element.children, value);
10         if (redata && redata.length > 0) {
11           let obj = {
12             ...element,
13             children: redata
14           };
15           newarr.push(obj);
16         }
17       }
18     }
19   });
20   return newarr;
21 };

 

posted @ 2024-08-13 14:59  鼓舞飞扬  阅读(3)  评论(0编辑  收藏  举报