标签:namespace getchild nod system list() collect HERE 节点 lis
using System;
using System.Collections.Generic;
using System.Text;
using WeChatApi.Model;
using System.Linq;
namespace Help
{
public static class TreeGridHelper
{
//递归获取所有树结构的数据
public static IList<TreeGridModel> GetData(this List<TreeGridModel> data)
{
List<TreeGridModel> nodes = data.Where(x => x.parentId == "0").Select(x => new TreeGridModel { id = x.id, parentId = x.parentId, name = x.name,code = x.code,orderNumber = x.orderNumber ,remark = x.remark}).ToList();
foreach (TreeGridModel item in nodes)
{
item.children = GetChildrens(item, data);
}
return nodes;
}
//递归获取子节点
public static IList<TreeGridModel> GetChildrens(TreeGridModel data, List<TreeGridModel> dataList)
{
IList<TreeGridModel> childrens = dataList.Where(c => c.parentId == data.id).Select(x => new TreeGridModel { id = x.id, parentId = x.parentId, name = x.name, code = x.code, orderNumber = x.orderNumber, remark = x.remark }).ToList();
foreach (TreeGridModel item in childrens)
{
item.children = GetChildrens(item, dataList);
}
return childrens;
}
}
}
标签:namespace getchild nod system list() collect HERE 节点 lis
原文地址:https://www.cnblogs.com/qingfenglin/p/10531010.html