验证中...
Languages: C#
Categories: 编程语言基础
Latest update 2019-09-12 08:39
gistfile1.txt
Raw Copy
/// <summary>
/// 父子节点
/// </summary>
public class NodeList
{
public int Id { get; set; }
public string Name { get; set; }
public int ParId { get; set; }
public List<NodeList> SonNode { get; set; }
}
/// <summary>
/// 递归树 取所有数据
/// </summary>
/// <param name="nodeList">父节点</param>
/// <param name="listResult">可有可无,根据程序需要获取的</param>
/// <returns></returns>
public static NodeList CreateNodeList(NodeList nodeList, List<DeviceAarmType> listResult)
{
// 根据父节点id取到其子节点
var sonNodeList = listResult.Where(p => p.Id == nodeList.Id).ToList();
List<NodeList> response = new List<NodeList>();
// 如果此节点下没有子节点,返回
if (sonNodeList == null)
{
return null;
}
sonNodeList.ForEach(item =>
{
NodeList node = new NodeList();
node.Id = item.Id;
node.Name = item.Name;
//递归查询
response.Add(node);
CreateNodeList(node, listResult); // node 已经查到的父节点的id作为下一次查询的父节点
});
nodeList.SonNode = response; // 子节点为查询后的节点
return nodeList;
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search