树形图菜单级多级菜单显示
来源:互联网 发布:上传文件夹到linux 编辑:程序博客网 时间:2024/04/23 17:54
jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/back/comm.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/time-text/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/themes/icon.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/dialog4/artDialog.js?skin=blue"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/dialog4/plugins/iframeTools.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/demo/demo.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/back/table-ghhs.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/back/My97DatePicker/WdatePicker.js" language="javascript"></script>
<script type="text/javascript">
function Add(){
$("#formadd").ajaxSubmit({
url:"<%= request.getContextPath()%>/jurisdiction/add.do",
type:"post",
resetForm:false,
success:function(data){
if(data=="ok"){
//获取父窗口的window对象
var win = art.dialog.open.origin;
//调用父窗口的js方法refresh();
win.refresh();
//关闭对话框
art.dialog.close();
}
},
error:function(xhr,textStatus,errorThrown){
alert("新增权限失败,请重试");
}
});
}
</script>
<!-- <script type="text/javascript">
$(function(){
$(".pmenu").click(function(){
var chk = this;
$(this).parent().next().find(":checkbox").each(function(i, item){
item.checked = chk.checked;
});
});
});
</script> -->
<script type="text/javascript">
function getChecked() {
var nodes = $('#tt').tree('getChecked');
var s = '';
for (var i = 0; i < nodes.length; i++) {
if (s != '') s += ',';
s += nodes[i].text;
}
alert(s);
}
</script>
</head>
<body>
<form id="formadd">
<div class="easyui-tabs" style="width: 100%;">
<div title="权限基本信息">
<div class="dialog-table">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tk_table">
<tr>
<td width="100px"><span class="font01 pr5">*</span>角色名称:</td>
<td class="white-tr">
<input type="text" class="form-text" id="txtdeptname" name="rolename" />
</td>
</tr>
<tr>
<td width="100px"><span class="font01 pr5">*</span>权限信息:</td>
<td class="white-tr">
<%--
<c:forEach items="${menus }" var="menu">
<c:if test="${menu.parentfunid==null }">
<div>
<h4><input type="checkbox" class="pmenu" />${ menu.funname }</h4>
<div>
<c:forEach items="${menus }" var="submenu">
<c:if test="${submenu.parentfunid==menu.funid }">
<span>
<input name="funids" value="${submenu.funid }" type="checkbox" />${ submenu.funname }
</span>
</c:if>
</c:forEach>
</div>
</div>
</c:if>
</c:forEach> --%>
<div data-options="region:'center',split:true" title="权限树" style="padding: 5px">
<ul id="tt" class="easyui-tree" data-options="url:'<%= request.getContextPath()%>/jurisdiction/tree.json',method:'get',animate:true,checkbox:true"></ul>
</div>
<%-- <div class="easyui-panel" style="padding:5px">
<ul id="tt" class="easyui-tree" data-options="url:'<%= request.getContextPath() %>/jurisdiction/tree.json',method:'get',animate:true,checkbox:true"></ul>
</div>
--%>
</td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
Controller实例
//权限树
List<NodelTree> nodes=null;
@ResponseBody
@RequestMapping(value="/tree.json",method=RequestMethod.GET)
public List<NodelTree> tree(HttpServletResponse resp) throws Exception{
List<Functionmenu> functList =functionmenuService.getAllfunctionmenu();
nodes = new ArrayList<NodelTree>();
for(Functionmenu fun :functList){
if(fun.getParentfunid()==null || fun.getParentfunid()==0){
NodelTree nodetree = new NodelTree();
nodetree.setId(fun.getFunid());
nodetree.setText(fun.getFunname());
nodes.add(nodetree);
}
}
setChildrenMenu(functList,nodes);
/*ObjectMapper mapper = new ObjectMapper();
String json=mapper.writeValueAsString(node);
System.out.println(json);
resp.getWriter().write(json);*/
return nodes;
}
private void setChildrenMenu(List<Functionmenu> allMenu,List<NodelTree> parentNodes){
List<Functionmenu> functList =functionmenuService.getAllfunctionmenu();
for(NodelTree node :parentNodes){
for(Functionmenu fun :functList){
if(fun.getParentfunid()==node.getId()){
NodelTree child = new NodelTree();
child.setId(fun.getFunid());
child.setText(fun.getFunname());
node.getChildren().add(child);
}
}
setChildrenMenu(allMenu,node.getChildren());
}
}
注意:实体类中
package com.wskj.ssm.util;
import java.util.ArrayList;
import java.util.List;
public class NodelTree {
private Integer id;
private String text;
private List<NodelTree> children=new ArrayList<NodelTree>();
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public List<NodelTree> getChildren() {
return children;
}
public void setChildren(List<NodelTree> children) {
this.children = children;
}
}
- 树形图菜单级多级菜单显示
- 多级树形菜单设计
- ExpandableListView---多级树形菜单
- js树形多级菜单
- 多级树形菜单的实现
- 多级树形菜单的实现
- ListView实现多级树形菜单
- Android多级树形菜单的实现
- Android---多级树形菜单的实现
- 菜单多级
- 多级菜单
- 多级菜单
- 多级菜单
- 多级菜单
- 多级下拉菜单的级连显示问题
- 多级下拉菜单的级连显示问题
- 在下拉框中显示树形菜单
- 无限级树形菜单
- 一个项目中的多个类中可以包含main()
- #define 高级用法(Ex) __FILE__ __FUNCTION__ __LINE__
- UNIX 进程--多任务原理
- MyEclipse快捷键大全
- 类初始化的顺序问题
- 树形图菜单级多级菜单显示
- sm指令分析
- mate9 的调节
- 表达式求值 递归实现(c/c++)
- 著名的北邮ACM推荐50题
- Longest Palindromic Substring
- session与cookie使用区别
- 深入理解三次握手与四次挥手
- 2017阿里技术一面总结(渣硕实习春招之路,美团offer)