function treeListToList(treeList) { // 将树结构的列表转换为普通列表 let list = []; handleTreeList(treeList, list); return list }
function handleTreeList(treeList, list) { if (!treeList || !treeList.length) { return } for (let i = 0; i < treeList.length; i++) { let currentRow = treeList[i]; let newRow = JSON.parse(JSON.stringify(currentRow)); newRow.children = undefined; list.push(newRow); handleTreeList(currentRow.children, list) } }