码迷,mamicode.com
首页 > Web开发 > 详细

递归实现jsonTree

时间:2019-03-14 16:50:18      阅读:192      评论:0      收藏:0      [点我收藏+]

标签: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;
}
}
}

递归实现jsonTree

标签:namespace   getchild   nod   system   list()   collect   HERE   节点   lis   

原文地址:https://www.cnblogs.com/qingfenglin/p/10531010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!