C# 树形结构tree拼接
2020-12-22 01:27
标签:service each where vat get project add 调用 span 实体类: 结果 C# 树形结构tree拼接 标签:service each where vat get project add 调用 span 原文地址:https://www.cnblogs.com/shijiehaiyang/p/13691171.htmlpublic class Project
{
public Project()
{
children = new List
id
parentId
name
1
-1
name1
2
1
name2
3
1
name3
4
2
name4
public List
//关键1: 传入的model是对象,对象修改会直接影响引用的对象
//关键2: 递归调用,直到传入的列表为空
private Project AddProjectChildren(Project model, List
[
{
"children": [
{
"children": [
{
"children": [],
"id": 4,
"parentId": 2,
"name": "name4",
},
],
"id": 2,
"parentId": 1,
"name": "name2",
},
{
"children": [],
"id": 3,
"parentId": 1,
"name": "name3",
}
],
"id": 1,
"parentId": -1,
"name": "name1",
}
]