把LIST递归成树形结构

把LIST递归成树形结构

2023年6月22日发(作者:)

把LIST递归成树形结构1.创建类 public class Node { public bool leaf { get; set; } public int FolderID { get; set; } public string iconCls { get; set; } public bool editable { get; set; } public bool expanded { get; set; } public int ParentFolderID { get; set; } public string text { get; set; } public bool InheritPerm { get; set; } //public string CreateDate { get; set; } //public string CreateBy { get; set; } public Node[] children { get; set; } }2.从数据库获取数据转化成LIST3.递归构建树形结构 public static string GetTree(List nodes) { var list = l(a => FolderID == 1);//最顶级的⽬录 foreach (var node in list) { if ( == "01.通讯录") { en = new Node[] { };//必须为空数组,不能为NULL,否则前端树节点会有错误 } GetTree(node, nodes); } return izeObject(list); } public static void GetTree(Node paretnNode, List nodes) { List nodelist = new List(); foreach (var node in nodes) { if (FolderID == ID) { GetTree(node, nodes); if (en == null) { en = new Node[] { };//必须为空数组,不能为NULL,否则前端树节点会有错误 } (node); en = y(); } } }

发布者:admin,转转请注明出处:http://www.yc00.com/web/1687385079a6106.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信