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