public class MenuTree { public long id { get; set; } public string text { get; set; } public string icon { get; set; } public string route { get; set; } public List<MenuTree> children = new List<MenuTree>(); /// <summary> /// 递归生成树形菜单 /// </summary> /// <param name="menuList">菜单数据</param> /// <param name="parenId">父级ID</param> /// <returns></returns> public static List<MenuTree> CreateTree(List<Menu> menuList, long parenId = 0) { var resources = menuList.Where(m => m.ParentId == parenId).Select(s => new MenuTree { id = s.Id, text = s.Name, route = s.Nickname ?? "" }).ToList(); if (resources.Count > 0) { var data = new List<MenuTree>(); resources.ForEach(t => { t.children = CreateTree(menuList, t.id); data.Add(t); }); return data; } return new List<MenuTree>(); } }
版权归属:
管理员
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区