private List<PermissionModel> GetMenu(List<PermissionModel> list, long pid)
{
Func<long, List<PermissionModel>> func = null;
func = new Func<long, List<PermissionModel>>(m =>
{
List<PermissionModel> t = new List<PermissionModel>();
foreach (var item in list.Where(h => h.ParentId == m))
{
var childs = func(item.Id);
PermissionModel model = new PermissionModel();
model.Id = item.Id;
model.Url = item.Url;
model.Icon = item.Icon;
model.Title = item.Title;
model.Param = item.Param;
model.ParentId = item.ParentId;
model.PermissionType = item.PermissionType;
model.Sort = item.Sort;
model.Children = childs.OrderBy(i => i.Sort).ToList();
t.Add(model);
}
t = t.OrderBy(i => i.Sort).ToList();
return t;
});
return func(pid);
}
解释:初次调用传入参数:list,pid。
list:从数据库中查出的菜单集合
pid:一级菜单的父ID,比如:0