62,254
社区成员
发帖
与我相关
我的任务
分享public void GetAllTreeView()
{
EasyUIJsonTree root = new EasyUIJsonTree()
{
text = "菜单根节点"
};
IList<Model.MenuView> list = bll.FindAllView(this.Application.AppID);
if (list != null && list.Count > 0)
{
this.GetTree(root, list);
}
Response.Write(JsonConvert.SerializeObject(new EasyUIJsonTree[] { root }));
}
private void GetTree(EasyUIJsonTree parent, IList<Model.MenuView> list, int? parentID = null)
{
var query = list.Where(m => m.Menu.ParentModuleID == parentID);
if (query.Any())
{
if (parent.children == null)
{
parent.children = new List<EasyUIJsonTree>();
}
foreach (Model.MenuView mv in query)
{
EasyUIJsonTree child = new EasyUIJsonTree()
{
id = mv.ModuleID.ToString(),
text = mv.ModuleName,
attributes = new { Url = mv.Url }
};
parent.children.Add(child);
this.GetTree(child, list, mv.ModuleID);
}
}
}
public class EasyUIJsonTree
{
public string id { get; set; }
public string text { get; set; }
//public string iconCls { get; set; }
public IList<EasyUIJsonTree> children { get; set; }
public object attributes { get; set; }
}