zoukankan      html  css  js  c++  java
  • js将树形结构的数组扁平化(按顺序)

        treeData(arr) {
            let cloneData = JSON.parse(JSON.stringify(arr))   //先将原来的数组深拷贝一份,防止影响到原来的数据
            return cloneData.filter(father => {
                let branchArr = cloneData.filter(child => father.id == child.parentId);
                branchArr.length > 0 ? father.children = branchArr : ''
                return father.parentId == null    //返回第一层的数据,如果最上一级的父级id不是null,请自行修改
            })
        }
     
    调用 this.treeData(json数组)
  • 相关阅读:
    raw socket
    selenium and win32api
    linux ip
    network config
    grub paramiter & menu.list
    实用命令dd
    resin or tomcat .war e.g. note
    JSP 运行
    linux command screen
    docker interact example
  • 原文地址:https://www.cnblogs.com/yzyuan/p/13203887.html
Copyright © 2011-2022 走看看