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

首頁 > 開發 > JS > 正文

JQuery ztree 異步加載實例講解

2024-05-06 16:29:14
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了JQuery ztree異步加載實例,感興趣的小伙伴們可以參考一下
 

本來要做一個文件目錄瀏覽界面,需要遍歷所有的文件和目錄,很顯然一次性讀取時很費時費力的一件事情。

因此就需要做異步加載....

準備工作:

1下載 JQuery ZTree

復制其中的JS和CSS即可,其實沒必要引那么多,用什么引什么就可以。

JQuery ztree 異步加載實例講解

2 需要fastJSON,用來轉換JSON對象

  我下載JAR包后,引入到Eclipse中總是報找不到class錯誤。

  解決辦法:把jar包放在WEB-INF/lib下即可。

代碼實例:

index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title>  <link rel="stylesheet" href="resources/css/demo.css" type="text/css">  <link rel="stylesheet" href="resources/css/zTreeStyle/zTreeStyle.css" type="text/css">  <script type="text/javascript" src="resources/js/jquery-1.4.4.min.js"></script>  <script type="text/javascript" src="resources/js/jquery.ztree.core-3.5.js"></script>  </head><body>  <div class="zTreeDemoBackground left">    <ul id="treeDemo" class="ztree"></ul>  </div>  <SCRIPT type="text/javascript">    var setting = {         data: {           simpleData: {             enable: true           }         } ,        async: {          enable: true,          url:"/TestZTree/test",          autoParam:["id", "name", "level"],          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(//.n/g, '.');      }      return childNodes;    }    var zNodes =[       { id:1, pId:0, name:"parentNode 1", open:true},       { id:11, pId:1, name:"parentNode 11",isParent:true},       { id:111, pId:11, name:"leafNode 111"},       { id:112, pId:11, name:"leafNode 112"},       { id:12, pId:1, name:"parentNode 12",isParent:true},       { id:121, pId:12, name:"leafNode 121"},       { 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></body></html>

 

testServlet.java

package com.test;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;public class testServlet extends HttpServlet{  @Override   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {     doPost(request, response);   }    @Override   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {     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);          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);     }     response.getWriter().write(JSON.toJSONString(list));   } }

 

web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5"   xmlns="http://java.sun.com/xml/ns/javaee"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet>  <servlet-name>testServlet</servlet-name>  <servlet-class>com.test.testServlet</servlet-class> </servlet> <servlet-mapping>  <servlet-name>testServlet</servlet-name>  <url-pattern>/test</url-pattern> </servlet-mapping>    <welcome-file-list>  <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>

 

效果圖:

JQuery ztree 異步加載實例講解

以上就是關于jquery異步加載,希望對大家學習jquery程序設計有所幫助。



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长顺县| 杭州市| 额敏县| 苏州市| 肥城市| 昭苏县| 婺源县| 宁海县| 贡嘎县| 伊吾县| 湘潭县| 通州市| 大姚县| 怀宁县| 杂多县| 日喀则市| 衡阳市| 永清县| 连平县| 广灵县| 龙门县| 阿坝| 克什克腾旗| 玉溪市| 盖州市| 南通市| 英山县| 福泉市| 格尔木市| 北辰区| 广宗县| 丽水市| 衢州市| 奉化市| 迁安市| 宁南县| 东阿县| 尼勒克县| 旺苍县| 蒙阴县| 资中县|