1 先获取1级菜单集合
/// <summary>
/// 获取菜单列表
/// </summary>
/// <returns></returns>
public List<MenuInfo> GetMenuList()
{
List<MenuInfo> departments = new List<MenuExt>();
List<MenuInfoExt> 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<MenuInfo> AddChildNode(List<MenuInfoExt> list, long departmentId)
{
List<MenuInfo> departments = new List<MenuInfo>();
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;
}