js樹型結構資料簡易遞迴

OneNightStand發表於2024-10-17

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 }

相關文章