zoukankan      html  css  js  c++  java
  • 关于ztree异步加载的问题(二)

    本来以为这个异步加载会很难控制,因为考虑到ztree节点图标的控制,结果并不是那么困难,ztree自己控制图标,你只要在json中设置isParent:true,它自己会识别父节点并控制图标,以下是核心代码:

    <!--前台js代码以及html-->
    //参数设置
    var setting={
            async: {
              enable: true,
              url:"${pageContext.request.contextPath}/page/department_ascyDepartment.do",
              autoParam:["id"]
            },
         simpleDate: {
               enable:true,
               idKey:"id",
               idPKey:"parentId",
               rootPid:null
         }
       };
    //一切预备好后初始化树
     $(document).ready(function(){  
           //创建对象
        var  demoTree = $.fn.zTree.init($("#treeDemo"), setting);
    });
     
    .....
     <div class="content_wrap">
     <div class="zTreeDemoBackground left">
       <ul id="treeDemo" class="ztree"  style="margin-left:10px;background-color:white;" >
         <img alt="请稍后,正在加载数据……" src="<%=basePath%>images/loading.gif"/>
       </ul>
     </div>
    .....
    <!--后台代码 json数据封装-->
     public void  ascyDepartment(){
       JSONArray jsonArr=new JSONArray();
       try {
          pId=getRequest().getParameter("id");
          Map<String,String> map=new HashMap<String, String>();
          map.put("pId", pId);
          List<Department> departs=departmentService.getChildNodes(map);
           for(Department depart:departs){
           JSONObject json=new JSONObject();
            json.put("id",depart.getId());
            json.put("name", depart.getName());
            json.put("parentId", depart.getParentId());
            if(depart.getHasChild()!=null){
               json.put("isParent", true);
              }
               jsonArr.add(json);
           }
       HttpServletResponse response=getResponse();
       response.setCharacterEncoding("utf-8");
       response.getWriter().print(jsonArr.toString());
       } catch (Exception e) {
         e.printStackTrace();
       }
     }

    本文转自:http://blog.sina.com.cn/s/blog_8a97a8d501011ejk.html

  • 相关阅读:
    SQL常用语句(不定期更新)包含 日期格式,取列
    前端开发 ---浏览器自动刷新
    记录Redis使用中遇到的两个问题(原子性及数据完整性)
    Linux 输出重定向
    逆向手机内核,添加调试支持及绕过反调试
    阿里2014移动安全挑战赛第二题调试笔记
    在redhat6.4上编译z3求解器
    WCF学习笔记一(概述)
    DataReader反射泛型对象
    自定义配置节点(一)
  • 原文地址:https://www.cnblogs.com/dreammyle/p/4018364.html
Copyright © 2011-2022 走看看