国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

jquery zTree異步加載簡單實例講解

2024-05-06 16:29:16
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了jquery zTree異步加載簡單實例,ztree采用了延遲加載技術,上萬節點輕松加載,即使在 IE6 下也能基本做到秒殺,感興趣的小伙伴們可以參考一下
 

本文實例講解了jquery zTree異步加載,分享給大家供大家參考,具體內容如下

web.xml中Servlet配置如下:

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4"    xmlns="http://java.sun.com/xml/ns/j2ee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">         <servlet>     <servlet-name>getDataServlet</servlet-name>;      <servlet-class>testTree.TestTree</servlet-class>;    </servlet>      <servlet-mapping>   <servlet-name>getDataServlet</servlet-name>;    <url-pattern>/getData</url-pattern>;    </servlet-mapping>  </web-app> 

JSP頁面:

<!DOCTYPE html> <HTML> <HEAD>   <TITLE> ZTREE DEMO - Simple Data</TITLE>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <link rel="stylesheet" href="css/demo.css" type="text/css">   <link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">   <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>   <script type="text/javascript" src="js/jquery.ztree.core-3.2.js"></script>   <script type="text/javascript" src="js/jquery.ztree.excheck-3.2.js"></script>   <script type="text/javascript" src="js/jquery.ztree.exedit-3.2.js"></script>   <SCRIPT type="text/javascript">     <!--     var setting = {       data: {         simpleData: {           enable: true         }       }       ,async: {         enable: true,         url:"/testJQuery/getData",         autoParam:["id", "name"],         otherParam:{"otherParam":"zTreeAsyncTest"},         dataFilter: filter       }     };     function filter(treeId, parentNode, childNodes) {       if (!childNodes) return null;       for (var i=0, l=childNodes.length; i<l; i++) {         childNodes[i].name = childNodes[i].name.replace('','');       }       return childNodes;     }     var zNodes =[       { id:1, pId:0, name:"parentNode 1", open:true},       { id:11, pId:1, name:"parentNode 11"},       { id:111, pId:11, name:"leafNode 111"},       { id:112, pId:11, name:"leafNode 112"},       { id:113, pId:11, name:"leafNode 113"},       { id:114, pId:11, name:"leafNode 114"},       { id:12, pId:1, name:"parentNode 12"},       { id:121, pId:12, name:"leafNode 121"},       { id:122, pId:12, name:"leafNode 122"},       { id:123, pId:12, name:"leafNode 123"},       { id:13, pId:1, name:"parentNode 13", isParent:true},       { id:2, pId:0, name:"parentNode 2", isParent:true}     ];      $(document).ready(function(){       $.fn.zTree.init($("#treeDemo"), setting, zNodes);     });     //-->   </SCRIPT>  </HEAD>  <BODY> <h1>最簡單的樹 -- 簡單 JSON 數據</h1> <h6>[ 文件路徑: core/simpleData.html ]</h6> <div class="content_wrap">   <div class="zTreeDemoBackground left">     <ul id="treeDemo" class="ztree"></ul>   </div> </div> </BODY> </HTML>

 Action代碼:

public class TestTree extends HttpServlet {    @Override   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //   System.out.println("--------doGet--------");     this.doPost(request, response);   }    @Override   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //   System.out.println("--------doPost--------");     String id = request.getParameter("id");     String name = request.getParameter("name");     String level = request.getParameter("level");     String otherParam = request.getParameter("otherParam");     System.out.println(id + "|" + name + "|" + level + "|" + otherParam);          JSONObject json = new JSONObject();     List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>();          for(int i = 0; i < 5; i++){       HashMap<String,Object> hm = new HashMap<String,Object>();  //最外層,父節點             hm.put("id", id + i);//id屬性 ,數據傳遞        hm.put("name", id + i); //name屬性,顯示節點名稱        hm.put("pId", id);              list.add(hm);     }          JSONArray arr = new JSONArray(list);     json.put("success", true);     json.put("arr", arr);          System.out.println("--------json------" + json.toString());     response.getWriter().write(arr.toString()); //   response.getWriter().write(json.toString()); //   response.getWriter().write("[{pId:'2',name:'20',id:'20'}]");   }  } 

以上就是jquery zTree異步加載實例分享給大家,希望對大家學習異步加載技術有所幫助。



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河间市| 普安县| 绵阳市| 九江县| 封开县| 孝感市| 即墨市| 新建县| 昆山市| 望谟县| 肃南| 社旗县| 灌南县| 株洲市| 车致| 明光市| 独山县| 德安县| 承德县| 莱西市| 收藏| 南华县| 武胜县| 沙湾县| 沧源| 罗甸县| 洛宁县| 河北省| 越西县| 汝阳县| 容城县| 汶川县| 华阴市| 洪泽县| 蒙阴县| 陆河县| 威宁| 平利县| 南靖县| 彰武县| 宾川县|