需求:知道某一对象数据需要知道它在哪个list中
[
{
"id":"1",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"0",
"projectCode":"01",
"projectName":"测试1",
"projectFeature":"特征1",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"12.00",
"totalPrice":"5.00",
"tempPrice":"4.00",
"drawCount":123,
"controlCount":"11.00",
"source":1,
"children":[
{
"id":"2",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"1",
"projectCode":"01-01",
"projectName":"测试2",
"projectFeature":"特征2",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"10.00",
"totalPrice":"4.00",
"tempPrice":"5.00",
"drawCount":11,
"controlCount":"22.00",
"source":1,
"children":[
]
},
{
"id":"3",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"1",
"projectCode":"01-02",
"projectName":"测试3",
"projectFeature":"特征3",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"11.00",
"totalPrice":"2.00",
"tempPrice":"6.00",
"drawCount":10,
"controlCount":"33.00",
"source":1,
"children":[
{
"id":"4",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"3",
"projectCode":"01-02-01",
"projectName":"测试4",
"projectFeature":"特征4",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"15.00",
"totalPrice":"1.00",
"tempPrice":"7.00",
"drawCount":20,
"controlCount":"44.00",
"source":1,
"children":[
]
}
]
}
]
},
{
"id":"5",
"createUser":"-1",
"createUserName":"",
"createDept":"-1",
"createTime":"",
"updateUser":"1123598821738675201",
"updateTime":"2021-08-03 21:15:18",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"0",
"projectCode":"02",
"projectName":"测试5",
"projectFeature":"特征5",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"12.00",
"totalPrice":"1.00",
"tempPrice":"23.00",
"drawCount":30,
"controlCount":"55.00",
"source":2,
"children":[
]
}
]
{
"id":"1",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"0",
"projectCode":"01",
"projectName":"测试1",
"projectFeature":"特征1",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"12.00",
"totalPrice":"5.00",
"tempPrice":"4.00",
"drawCount":123,
"controlCount":"11.00",
"source":1,
"children":[
{
"id":"2",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"1",
"projectCode":"01-01",
"projectName":"测试2",
"projectFeature":"特征2",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"10.00",
"totalPrice":"4.00",
"tempPrice":"5.00",
"drawCount":11,
"controlCount":"22.00",
"source":1,
"children":[
]
},
{
"id":"3",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"1",
"projectCode":"01-02",
"projectName":"测试3",
"projectFeature":"特征3",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"11.00",
"totalPrice":"2.00",
"tempPrice":"6.00",
"drawCount":10,
"controlCount":"33.00",
"source":1,
"children":[
{
"id":"4",
"createUser":-1,
"createUserName":"",
"createDept":-1,
"createTime":"",
"updateUser":-1,
"updateTime":"",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"3",
"projectCode":"01-02-01",
"projectName":"测试4",
"projectFeature":"特征4",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"15.00",
"totalPrice":"1.00",
"tempPrice":"7.00",
"drawCount":20,
"controlCount":"44.00",
"source":1,
"children":[
]
}
]
}
]
},
{
"id":"5",
"createUser":"-1",
"createUserName":"",
"createDept":"-1",
"createTime":"",
"updateUser":"1123598821738675201",
"updateTime":"2021-08-03 21:15:18",
"status":-1,
"isDeleted":0,
"mainProjectId":"1",
"parentId":"0",
"projectCode":"02",
"projectName":"测试5",
"projectFeature":"特征5",
"unit":"元",
"projectCount":"100.00",
"unitPrice":"12.00",
"totalPrice":"1.00",
"tempPrice":"23.00",
"drawCount":30,
"controlCount":"55.00",
"source":2,
"children":[
]
}
]
思路:
1.递归查找数据源
2.因为return的原因,需要定义个全局变量
注意事项:
1.return 值问题
2.跳出循环
代码:
![](https://img2020.cnblogs.com/blog/1515575/202108/1515575-20210803213437665-2110336360.png)