C#递归计算树形菜单

2021-06-09 05:04

阅读:610

标签:nts   inf   list   order   lis   sum   ==   vat   summary   

1 先获取1级菜单集合

 

///


/// 获取菜单列表
///

///
public List GetMenuList()
{
List departments = new List();
List menuinfoses =
_menuinfoRepository.Queryable().OrderBy("MenuId").Select(p => new MenuInfoExt()
{
ParentMenuId=p.ParentMenuId,
MenuId = p.MenuId,
Name = p.Name
}).ToList();
foreach (var item in menuinfoses)
{
if (item.ParentMenuId == 0)
{
MenuInfodepartment = new MenuInfo();
department.id = item.MenuId;
department.text = item.Name;
department.children = AddChildNode(menuinfoses, item.MenuId);
departments.Add(department);
}

}
return departments;

}

 

 

private List AddChildNode(List list, long departmentId)
{
List departments = new List();

foreach (var item in list.Where(p => p.ParentMenuId == departmentId))
{
MenuInfodepartment = new MenuInfo();
department.id = item.MenuId;
department.text = item.Name;
department.children = AddChildNode(list, item.MenuId);
departments.Add(department);
}
return departments;
}

C#递归计算树形菜单

标签:nts   inf   list   order   lis   sum   ==   vat   summary   

原文地址:https://www.cnblogs.com/dyc-zlj/p/10668283.html


评论


亲,登录后才可以留言!