• 递归获取所有JSON对象


    递归获取所有JSON对象

    <script>
            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)
        </script>
    
    
  • 相关阅读:
    发布新闻
    下拉列表联动显示(Car表) 三级联动
    下拉列表联动显示(中国省市)三级联动
    MVC——数据库增删改查(Razor)——Html语法
    MVC——数据库增删改查(Razor)
    MVC——数据库增删改查(aspx)
    ASP.NET MVC 4 (五) 视图
    ASP.NET MVC 4 (四) 控制器扩展
    ASP.NET MVC 4 (三) 过滤器
    ASP.NET MVC 4 (二)控制器
  • 原文地址:https://www.cnblogs.com/wgy0528/p/12655925.html
Copyright © 2020-2023  润新知