• js 过滤没有children的数据


    var arr=[{"id":"1","pids":"1","name":"企业","type":1,"children":[{"id":"5","pid":"1","pids":"1#5","name":"电商/团购","type":2,"children":[{"id":"8","pid":"5","pids":"1#5#8","name":"美妆护肤","type":2},{"id":"9","pid":"5","pids":"1#5#9","name":"健身器材","type":2},{"id":"f8109e9302e04a27a120a4b6f6533dc4","pid":"5","pids":"1#5#f8109e9302e04a27a120a4b6f6533dc4","name":"11","type":3}]},{"id":"6","pid":"1","pids":"1#6","name":"生活/家居","type":2}]},{"id":"2","pids":"2","name":"个体户","type":1,"children":[{"id":"7","pid":"2","pids":"2#7","name":"餐饮/食品","type":2}]},{"id":"3","pids":"3","name":"事业单位","type":1},{"id":"4","pids":"4","name":"其他组织","type":1},{"id":"6d4bde78241d47a19f4faae0e5f5e6b8","pids":"6d4bde78241d47a19f4faae0e5f5e6b8","name":"其他组织","type":1}]
    

    原始数据 =》过滤 只遍历到三级数据 假设判断如果一级到二级没有children就过滤下

    const tempList = arr.filter(res => {
          if (res.children && res.children.length) {
            const children = [];
            res.children.forEach((item, index) => {
              if (item.children && item.children.length) {
                children.push(item);
              }
            })
            if (children.length) {
              res.children = children;
              return res;
            }
          }
        });
    

      

  • 相关阅读:
    excel的导入导出
    mybatis常用sql
    java中和时间相关的类,方法
    <resultMap>
    项目启动报的错
    多表查询
    file的一些方法
    AOV网络与AOE网络
    封装解封装过程
    以太网交换机
  • 原文地址:https://www.cnblogs.com/alone2015/p/11864358.html
Copyright © 2020-2023  润新知