jquery zTree异步加载简单实例讲解

本文实例讲解了jquery zTree异步加载,分享给大家供大家参考,具体内容如下

web.xml中Servlet配置如下:

rush:xml;"> getDataServlet; testTree.TestTree; getDataServlet; /getData;

JSP页面

rush:xhtml;"> ZTREE DEMO - Simple Data <Meta http-equiv="content-type" content="text/html; charset=UTF-8">

最简单的树 -- 简单 JSON 数据

[ 文件路径: core/simpleData.html ]

Action代码

rush:java;"> 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,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<a href="https://www.jb51.cc/tag/shuxing/" target="_blank" class="keywords">属性</a> ,数据传递  
  hm.put("name",id + i); //name<a href="https://www.jb51.cc/tag/shuxing/" target="_blank" class="keywords">属性</a>,<a href="https://www.jb51.cc/tag/xianshi/" target="_blank" class="keywords">显示</a>节点<a href="https://www.jb51.cc/tag/mingcheng/" target="_blank" class="keywords">名称</a>  
  hm.put("pId",id); 

  list.add(hm); 
} 

JSONArray arr = new JSONArray(list); 
json.put("success",true); 
json.put("arr",arr); 

Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.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异步加载实例分享给大家,希望对大家学习异步加载技术有所帮助。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...