$(function($) { $('#tg').treegrid({ url:'<%=request.getContextPath()%>/sysMenu/list', rownumbers: false, treeField: 'name', checkbox:true,
ascadeCheck:true,//结连显示 idField:'id', emptyMsg:'无数据', columns:[[ {title:'id',field:'id',160,hidden:true}, {field:'action',title:'操作',formatter:formatAction,'15%'}, {title:'菜单名称',field:'name','25%',align:'left'}, {title:'菜单路径',field:'url','25%',align:'left'}, {title:'菜单排序值',field:'displayorder','15%',align:'left'}, {title:'创建日期',field:'createdate','25%',align:'left'}, {title:'修改日期',field:'modifydate','25%',align:'left'} ]] }); }); function formatAction(val,row){ return '<a style="" href="#" onclick="javascript:editMenu('+row.id+')"> 编辑</a>'; }
@RequestMapping("/list") public void list(HttpServletRequest request,HttpServletResponse response){ List<SysMenu> list = null; Map<String,Object> params = new HashMap<String,Object>(); gtSysUser user = (gtSysUser)request.getSession().getAttribute("user"); list = this.sysMenuService.list(params); SysMenu tempMenu = sysMenuService.selectByPrimaryKey(1); if(!list.contains(tempMenu)) { list.add(0,tempMenu); } List menuList = new ArrayList<Map>(); //根菜单 HashMap<String,Object> menuRootMap = new HashMap<>(); for(SysMenu menu : list){ if(menu.getParentid() == null || menu.getParentid() == 0){ menuRootMap.put("id", menu.getId()); menuRootMap.put("name", menu.getName()); menuRootMap.put("url", menu.getUrl()); menuRootMap.put("icon", menu.getIcon()); menuRootMap.put("displayorder", menu.getDisplayorder()); menuRootMap.put("createdate", menu.getCreatedate()); menuRootMap.put("modifydate", menu.getModifydate()); } }; ArrayList<Map<String,Object>> modalArray = new ArrayList<Map<String,Object>>(); for(SysMenu menuParent : list){ //二级模块 if(menuParent.getParentid() == menuRootMap.get("id")){ HashMap<String,Object> menuParentMap = new HashMap<String,Object>(); ArrayList<Map<String,Object>> childrenList = new ArrayList<Map<String,Object>>() ; menuParentMap.put("id", menuParent.getId()); menuParentMap.put("name", menuParent.getName()); menuParentMap.put("url", menuParent.getUrl()); menuParentMap.put("icon", menuParent.getIcon()); menuParentMap.put("displayorder", menuParent.getDisplayorder()); menuParentMap.put("createdate", menuParent.getCreatedate()); menuParentMap.put("modifydate", menuParent.getModifydate()); //菜单 for(SysMenu menuChildren : list){ if(menuChildren.getParentid().intValue() == menuParent.getId().intValue()){ HashMap<String,Object> menuChildrenMap = new HashMap<>(); menuChildrenMap.put("id", menuChildren.getId()); menuChildrenMap.put("name", menuChildren.getName()); menuChildrenMap.put("url", menuChildren.getUrl()); menuChildrenMap.put("icon", menuChildren.getIcon()); menuChildrenMap.put("displayorder", menuChildren.getDisplayorder()); menuChildrenMap.put("createdate", menuChildren.getCreatedate()); menuChildrenMap.put("modifydate", menuChildren.getModifydate()); childrenList.add(menuChildrenMap); ArrayList<Map<String,Object>> buttonChildrenList = new ArrayList<Map<String,Object>>(); //按钮 for(SysMenu menuButton : list){ if(menuButton.getParentid().intValue() == menuChildren.getId().intValue()){ HashMap<String,Object> buttonChildrenMap = new HashMap<>(); buttonChildrenMap.put("id", menuButton.getId()); buttonChildrenMap.put("name", menuButton.getName()); buttonChildrenMap.put("url", menuButton.getUrl()); buttonChildrenMap.put("icon", menuButton.getIcon()); buttonChildrenMap.put("displayorder", menuButton.getDisplayorder()); buttonChildrenMap.put("createdate", menuButton.getCreatedate()); buttonChildrenMap.put("modifydate", menuButton.getModifydate()); buttonChildrenList.add(buttonChildrenMap); } } menuChildrenMap.put("children", buttonChildrenList); } } menuParentMap.put("children", childrenList); modalArray.add(menuParentMap); } } menuRootMap.put("children", modalArray); menuList.add(menuRootMap); //HashMap<String,Object> messageMap = new HashMap<String,Object>(); //messageMap.put("rows", list); //this.out(response, messageMap); this.webOut(response, menuList); return; }