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

前端之家收集整理的这篇文章主要介绍了jquery zTree异步加载简单实例讲解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

web.xml中Servlet配置如下:

getDataServlet; testTree.TestTree; getDataServlet; /getData;

JSP页面

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

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

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

Action代码

@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); 

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异步加载实例分享给大家,希望对大家学习异步加载技术有所帮助。

原文链接:https://www.f2er.com/jquery/49958.html

猜你在找的jQuery相关文章