- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@include file="/common/jsp/commonHeader.jsp" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title><s:text name="dama_inforpartition_kpi_page_title"/></title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <link rel="stylesheet" href="<%=path %>/common/css/zTreeStyle.css">
- </head>
- <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.core-3.3.js"></script>
- <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.excheck-3.3.js"></script>
- <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.exedit-3.3.js"></script>
- <script type="text/javascript">
- var zTree1;
- var setting={
- data:{
- simpleData:{
- enable:true,
- idKey:'id',
- pIdKey:'pId',
- rootPId:-1
- }
- },
- view:{
- dblClickExpand:true,
- showLine:true
- },
- check:{
- chkboxType:{'Y':'p','N':'p'},
- chkStyle:'checkbox',
- enable:true
- }
- }
- function createTree(){
- $.ajax({
- url:'admin/kpiGroupAction!getChildrens',
- type:'POST',
- dataType:'text',
- ContentType:'application/json; charset=utf-8',
- success:function(data){
- var zNodes = data;
- var ztreeNodes = [{"id":"-1","name":"指标组管理","isParent":true},{"id":"104","name":"1234er4","isParent":true,"pId":"-1"},{"id":"106","name":"测试修改","isParent":false,"pId":"-1"},{"id":"02","name":"同城交友123","isParent":true,"pId":"-1"},{"id":"164","name":"cesgu","isParent":false,"pId":"02"},{"id":"182","name":"租房子","isParent":false,"pId":"181"},{"id":"108","name":"zhuangtianxiu","isParent":true,"pId":"-1"},{"id":"181","name":"房屋租赁","isParent":true,"pId":"-1"},{"id":"201","name":"123","isParent":false,"pId":"104"},{"id":"166","name":"haha ","isParent":false,"pId":"108"}];
- zTree1=$.fn.zTree.init($('#kpiTree'),setting,eval('(' + zNodes + ')'));
- },
- error:function(msg){
- alert('指标树加载异常!');
- }
- });
- }
- $(document).ready(function(){
- createTree();
- })
- </script>
- <body>
- <div>
- <ul id="kpiTree" class="ztree"></ul>
- </div>
- </body>
- </html>
action端代码:
- public String getChildrens(){
- JSONArray childs = new JSONArray();
- JSONObject child = new JSONObject();
- HttpServletResponse response = ServletActionContext.getResponse();
- response.setCharacterEncoding("utf-8");
- try {
- PrintWriter out = response.getWriter();
- String kpiGroupId = this.getModel().getKpiGroupId();
- Set<SyinfDamaKpiGroupT> childrens = new HashSet<SyinfDamaKpiGroupT>();
- if(kpiGroupId==null){
- childrens = service.getChildren("");
- }else{
- childrens = service.getChildren(this.getModel().getKpiGroupId());
- }
- for(SyinfDamaKpiGroupT childkpi:childrens){
- child.put("id", childkpi.getKpiGroupId());
- if(kpiGroupId==null){
- if(!childkpi.getKpiGroupId().equals("-1")){
- child.put("pId", childkpi.getParentGroup().getKpiGroupId());
- }
- }else{
- child.put("pId", this.getModel().getKpiGroupId());
- }
- child.put("name", childkpi.getKpiGroupName());
- if(kpiGroupId==null){
- if(childkpi.getChildGroup().size()>0){
- child.put("isParent", true);
- }else{
- child.put("isParent", false);
- }
- }else{
- if(childkpi.getChildGroup().size()>0){
- child.put("havechild", "yes");
- }else{
- child.put("havechild", "no");
- }
- }
- childs.add(child);
- }
- out.print(childs.toString());
- out.flush();
- out.close();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }