Struts2+json+ztree 同步加载

 
 
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 
  2. <%@include file="/common/jsp/commonHeader.jsp" %> 
  3.  
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
  5. <html> 
  6.   <head> 
  7.     <base href="<%=basePath%>"> 
  8.      
  9.     <title><s:text name="dama_inforpartition_kpi_page_title"/></title> 
  10.      
  11.     <meta http-equiv="pragma" content="no-cache"> 
  12.     <meta http-equiv="cache-control" content="no-cache"> 
  13.     <meta http-equiv="expires" content="0">     
  14.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
  15.     <meta http-equiv="description" content="This is my page"> 
  16.     <link rel="stylesheet" href="<%=path %>/common/css/zTreeStyle.css"> 
  17.   </head> 
  18.     <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.core-3.3.js"></script> 
  19.     <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.excheck-3.3.js"></script> 
  20.     <script type="text/javascript" src="<%=path %>/common/js/jquery.ztree.exedit-3.3.js"></script> 
  21.     <script type="text/javascript"> 
  22.         var zTree1; 
  23.         var setting={ 
  24.             data:{ 
  25.                 simpleData:{ 
  26.                     enable:true, 
  27.                     idKey:'id', 
  28.                     pIdKey:'pId', 
  29.                     rootPId:-1 
  30.                 } 
  31.             }, 
  32.             view:{ 
  33.                 dblClickExpand:true, 
  34.                 showLine:true 
  35.             }, 
  36.             check:{ 
  37.                 chkboxType:{'Y':'p','N':'p'}, 
  38.                 chkStyle:'checkbox', 
  39.                 enable:true 
  40.             } 
  41.         } 
  42.          
  43.         function createTree(){ 
  44.             $.ajax({ 
  45.                 url:'admin/kpiGroupAction!getChildrens', 
  46.                 type:'POST', 
  47.                 dataType:'text', 
  48.                 ContentType:'application/json; charset=utf-8', 
  49.                 success:function(data){ 
  50.                     var zNodes = data
  51.                         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"}]; 
  52.                     zTree1=$.fn.zTree.init($('#kpiTree'),setting,eval('(' + zNodes + ')')); 
  53.                 }, 
  54.                 error:function(msg){ 
  55.                     alert('指标树加载异常!'); 
  56.                 } 
  57.             }); 
  58.         } 
  59.         $(document).ready(function(){ 
  60.             createTree(); 
  61.         }) 
  62.     </script> 
  63.   <body> 
  64.     <div> 
  65.         <ul id="kpiTree" class="ztree"></ul> 
  66.     </div> 
  67.   </body> 
  68. </html> 

 

action端代码:

 

 
 
  1. public String getChildrens(){ 
  2.         JSONArray childs = new JSONArray(); 
  3.         JSONObject child = new JSONObject(); 
  4.         HttpServletResponse response = ServletActionContext.getResponse(); 
  5.         response.setCharacterEncoding("utf-8"); 
  6.         try { 
  7.             PrintWriter out = response.getWriter(); 
  8.             String kpiGroupId = this.getModel().getKpiGroupId(); 
  9.             Set<SyinfDamaKpiGroupT> childrens = new HashSet<SyinfDamaKpiGroupT>(); 
  10.             if(kpiGroupId==null){ 
  11.                 childrens = service.getChildren(""); 
  12.             }else
  13.                 childrens = service.getChildren(this.getModel().getKpiGroupId()); 
  14.             } 
  15.              
  16.             for(SyinfDamaKpiGroupT childkpi:childrens){ 
  17.                 child.put("id", childkpi.getKpiGroupId()); 
  18.                 if(kpiGroupId==null){ 
  19.                     if(!childkpi.getKpiGroupId().equals("-1")){ 
  20.                         child.put("pId", childkpi.getParentGroup().getKpiGroupId()); 
  21.                     } 
  22.                 }else
  23.                     child.put("pId"this.getModel().getKpiGroupId()); 
  24.                 } 
  25.                  
  26.                 child.put("name", childkpi.getKpiGroupName()); 
  27.                 if(kpiGroupId==null){ 
  28.                      
  29.                     if(childkpi.getChildGroup().size()>0){ 
  30.                         child.put("isParent"true); 
  31.                     }else
  32.                         child.put("isParent"false); 
  33.                     } 
  34.                 }else
  35.                     if(childkpi.getChildGroup().size()>0){ 
  36.                         child.put("havechild""yes"); 
  37.                     }else
  38.                         child.put("havechild""no"); 
  39.                     } 
  40.                 } 
  41.                  
  42.                  
  43.                 childs.add(child); 
  44.             } 
  45.             out.print(childs.toString()); 
  46.             out.flush(); 
  47.             out.close(); 
  48.         } catch (Exception e) { 
  49.             // TODO Auto-generated catch block 
  50.             e.printStackTrace(); 
  51.         } 
  52.         return null
  53.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值