JS 树型结构数据简易递归

js树型结构数据简易递归

// item内的值根据实际情况更换
replaceValueInTree (tree) {   const result
= []   tree.forEach((item) => {     let children = item.children || []     if (Array.isArray(children) && children.length > 0) {       children = this.replaceValueInTree(children)     }     let newItem = {       title: item.categoryName,       value: item.id,       checked: false,       selected: false,       children: children     }     result.push(newItem);   })   return result }

 

posted @ 2024-10-17 17:19  烧机  阅读(28)  评论(0编辑  收藏  举报