private void BuildTree(Tb_Role_Module_Tree root, IList <Tb_Role_Module_Tree> list) { if (root == null) { return; } var source = list; if (source == null) { return; } var children = source.Where(d => d.id_module_father == root.id_module); if (children == null) { return; } root.children = children.ToList(); foreach (var item in children) { BuildTree(item, source); } }
/// <summary> /// 获取角色模块树 /// </summary> /// <returns></returns> public IList <Tb_Role_Module_Tree> GetRoleModuleTree(Hashtable param) { if (!param.ContainsKey("id_platform_role")) { //默认为供应商 param.Add("id_platform_role", "0"); } param.Add("sort", "sort_id"); param.Add("dir", "asc"); var sourceList = DAL.QueryList <Tb_Role_Module_Tree>(typeof(Tb_Role_Module), param); var targetList = sourceList.Where(d => d.id_module_father == "0").ToList(); var root = new Tb_Role_Module_Tree { id = "0", id_module = "0", name = "根目录", children = targetList, isclose = false }; foreach (var item in targetList) { BuildTree(item, sourceList); } var rootList = new List <Tb_Role_Module_Tree>(); rootList.Add(root); return(rootList); }