| 12345678910111213141516171819202122232425262728293031 |
- using System.Collections.Generic;
- using System.Text;
- namespace RMYY_CallCenter_Api.Utility
- {
- public static class Tree
- {
- /// <summary>
- /// 递归算法
- /// </summary>
- /// <param name="data"></param>
- /// <param name="parentId"></param>
- /// <returns></returns>
- public static List<TreeModel> TreeRecursion(this List<TreeModel> data, string parentId = "0")
- {
- List<TreeModel> newList = new List<TreeModel>();
- List<TreeModel> 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;
- }
- }
- }
|