C#通用递归生成树形结构数据
2021-03-06 07:27
标签:str HERE void name param 调用 方法 span idf 1.首先定义树形结构类 2.利用反射将泛型list转换为树形结构类 3.递归方法 4.调用 5.处理后数据结果 C#通用递归生成树形结构数据 标签:str HERE void name param 调用 方法 span idf 原文地址:https://www.cnblogs.com/waxwt/p/12872762.html ///
///
///
List
//list为待处理数据集,pID为父级节点ID;然后分别传入待处理数据集中ID的字段名称,父级ID的字段名称和需要展示Name字段名称
treeViewModels = ConversionList(list, pID, "ID", "PID", "EFName");[{
"ID": "00000000-0000-0000-0000-000000000001",
"PARENTID": "00000000-0000-0000-0000-000000000000",
"NAME": "1级",
"TREECHILDREN": [{
"ID": "00000000-0000-0000-0000-000000000002",
"PARENTID": "00000000-0000-0000-0000-000000000001",
"NAME": "2级",
"TREECHILDREN": [{
"ID": "00000000-0000-0000-0000-000000000003",
"PARENTID": "00000000-0000-0000-0000-000000000002",
"NAME": "3级",
"TREECHILDREN": [{
"ID": "00000000-0000-0000-0000-000000000005",
"PARENTID": "00000000-0000-0000-0000-000000000003",
"NAME": "4级",
"TREECHILDREN": null
}]
}]
}]
},
{
"ID": "00000000-0000-0000-0000-000000000004",
"PARENTID": "00000000-0000-0000-0000-000000000000",
"NAME": "1级",
"TREECHILDREN": null
}
]
上一篇:jQuery调用api