using System.Collections.Generic; using System.Text; namespace RMYY_CallCenter_Api.Utility { public static class Tree { /// /// 递归算法 /// /// /// /// public static List TreeRecursion(this List data, string parentId = "0") { List newList = new List(); List item = data.FindAll(t => t.parentid == parentId);//data建议在调用此扩展方法前已经排序过 if (item.Count > 0) { foreach (TreeModel entity in item) { entity.children = TreeRecursion(data, entity.id); newList.Add(entity); } } return newList; } } }