private SysAppMenuTree getNode(SysAppMenu item, List <SysAppMenu> col3) { SysAppMenuTree node = new SysAppMenuTree() { id = item.id, menu_code = item.menu_code, app_id = item.app_id, title = item.title, parent_id = item.parent_id, icon = item.icon, menu_type = item.menu_type, jump = item.jump, is_enable = item.is_enable, sort = item.sort, group_id = item.group_id }; List <SysAppMenu> childs = col3.Where(t => t.parent_id == item.id).ToList(); if (childs.Count() > 0) { List <SysAppMenuTree> children = new List <SysAppMenuTree>(); foreach (var childitem in childs) { SysAppMenuTree childnode = getNode(childitem, col3); children.Add(childnode); } node.children = children; } return(node); }
public ResponseMessage <object> GetALL(string name) { List <object> reslst = new List <object>(); List <SysAppMenu> col1 = _sysAppMenuService.GetAll("").OrderBy(t => t.sort).ToList(); List <SysAppMenu> col2 = _sysAppMenuService.GetAll(name).OrderBy(t => t.sort).ToList(); SysAppMenu[] arr = new SysAppMenu[col2.Count()]; List <SysAppMenu> col3 = new List <SysAppMenu>(); col2.CopyTo(arr); col3 = arr.ToList(); foreach (var item in col2) { //补全树 getTree(col1, col3, item); } //构建树结果 foreach (SysAppMenu item in col3.Where(t => t.parent_id == "0")) { SysAppMenuTree node = getNode(item, col3); reslst.Add(node); } return(new ResponseMessage <object> { data = new { content = reslst } }); }