博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
递归获取所有JSON对象
阅读量:5307 次
发布时间:2019-06-14

本文共 1513 字,大约阅读时间需要 5 分钟。

let treeData=[

    {
        "ID":9601,
        "DeviceId":"99a9014e-a651-43ce-945c-c027e6235ab4",
        "DeviceName":"测试设备名称",
        "DeviceBrand":null,
        "DeviceTypeId":null,
        "DeviceLevel":1,
        "FactorySerial":"CS010",
        "CompanySerial":"CS010",
        "FModelSize":null,
        "Childers":[
            {
                "ID":9603,
                "DeviceId":"271b8edb-f836-49a6-a99a-09148a0547ea",
                "DeviceName":"测试设备名称_1",
                "DeviceBrand":null,
                "DeviceTypeId":null,
                "DeviceLevel":2,
                "FactorySerial":"CEMC1",
                "CompanySerial":"CEMC1",
                "FModelSize":null,
                "Childers":[
                ]
            }
        ]
    },
    {
        "ID":9604,
        "DeviceId":"18b6e21b-07aa-432d-843a-0f106b088b88",
        "DeviceName":"测试USB",
        "DeviceBrand":null,
        "DeviceTypeId":null,
        "DeviceLevel":1,
        "FactorySerial":"U_1",
        "CompanySerial":"U_1",
        "FModelSize":null,
        "Childers":[
            {
                "ID":9602,
                "DeviceId":"8c7081b5-67ae-4ef9-b150-524bbd2b81f9",
                "DeviceName":"测试设备名称",
                "DeviceBrand":null,
                "DeviceTypeId":null,
                "DeviceLevel":2,
                "FactorySerial":"CS010",
                "CompanySerial":"CS011",
                "FModelSize":null,
                "Childers":[
                    {
                        "ID":9607,
                        "DeviceId":"56a25da2-6e22-4c0d-9f99-79fed4ee9546",
                        "DeviceName":"测试设备名称_1",
                        "DeviceBrand":null,
                        "DeviceTypeId":null,
                        "DeviceLevel":3,
                        "FactorySerial":"U_4",
                        "CompanySerial":"U_4",
                        "FModelSize":null,
                        "Childers":[
                        ]
                    }
                ]
            }
        ]
    }
]
递归所有JSON push到新的数组
getTree(treeData){
  for(let i = 0; i < treeData.length; i++){
    this.dataInfoList.push(treeData[i])
    if(treeData[i].Childers && treeData[i].Childers.length > 0){
      this.getTree(treeData[i].Childers)
    }
  }
},
 console.log(this.dataInfoList)

 

 

©2014 JSON.cn All rig

转载于:https://www.cnblogs.com/wgy0528/p/11362983.html

你可能感兴趣的文章
20130330java基础学习笔记-语句_for循环嵌套练习2
查看>>
Spring面试题
查看>>
窥视SP2010--第一章节--SP2010开发者路线图
查看>>
C语言栈的实现
查看>>
代码为什么需要重构
查看>>
TC SRM 593 DIV1 250
查看>>
SRM 628 DIV2
查看>>
2018-2019-2 20165314『网络对抗技术』Exp5:MSF基础应用
查看>>
Python-S9-Day127-Scrapy爬虫框架2
查看>>
SecureCRT的使用方法和技巧(详细使用教程)
查看>>
右侧导航栏(动态添加数据到list)
查看>>
81、iOS本地推送与远程推送详解
查看>>
虚拟DOM
查看>>
自建数据源(RSO2)、及数据源增强
查看>>
关于View控件中的Context选择
查看>>
2018icpc徐州OnlineA Hard to prepare
查看>>
Spark的启动进程详解
查看>>
使用命令创建数据库和表
查看>>
机器视觉:SSD Single Shot MultiBox Detector
查看>>
201521123044 《Java程序设计》第1周学习总结
查看>>