zoukankan      html  css  js  c++  java
  • 数据处理

    1、问题描述:

      将当前数组中的(`name: '/'`)删除掉,并将当前children中的数组合并到父数组去。
    

    2、数据格式:

    
    var data = [{
      name: "A",
      children: [{
        name: "1",
        children: [{
            name: "01",
            children: [{
                name: "001",
                children: []
            }]
        }]
      }, {
        name: "2",
        pid: 1,
        children: [{
            name: "/",
            pid: 2,
            children: [{
                name: "002",
                pid: 3,
                children: [{
                    name: "0002",
                    pid: 4,
                    children: [{
                        name: "/",
                        pid: 5,
                        children: [{
                                name: "000002",
                                pid: 6,
                                children: []
                            }
      
                        ]
                    }]
      
                }]
            }]
        }]
    }, {
        name: "/",
        pid: 1,
        children: [{
            name: "/",
            pid: 2,
            children: [{
                name: "/",
                pid: 3,
                children: [{
                    name: "0003",
                    pid: 4,
                    children: []
                },{
                      name: "0003",
                      pid: 4,
                      children: []
                }]
            }]
        }]
      }]
    }]
    
    

    3、处理:通过递归方式,深度查找

    function filter(old) {
      let arr = [];
      old && old.forEach((item, index)=> {
        if(item.name === '/') {
          arr.push(...filter(item.children))
        } else {
          item.children = filter(item.children)
          arr.push(item);
        }
    
      })
      return arr;
    }
    console.log(filter(data))
    

    4、结果:

  • 相关阅读:
    序列化
    输入输出流——字符流部分
    输入输出流——字节流部分
    GitHub10岁之际HanLP自然语言处理包用户量跃居榜首
    hadoop大数据处理平台与案例
    dkhadoop的自然语言处理技术介绍
    hadoop大数据技术架构详解
    hadoop框架结构介绍
    Hadoop集群环境搭建步骤说明
    快速了解掌握中文自然语言处理
  • 原文地址:https://www.cnblogs.com/wangyong1997/p/13913247.html
Copyright © 2011-2022 走看看