其他分享
首页 > 其他分享> > js 将树结构的列表转换为普通列表

js 将树结构的列表转换为普通列表

作者:互联网

 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)
  }
}

  

标签:newRow,currentRow,树结构,handleTreeList,list,js,let,treeList,列表
来源: https://www.cnblogs.com/houBlogs/p/15329292.html