Home Web Front-end JS Tutorial Jquery zTree tree control asynchronous loading operation_jquery

Jquery zTree tree control asynchronous loading operation_jquery

May 16, 2016 pm 03:13 PM
jquery Asynchronous loading

zTree uses the core code of JQuery to implement a set of Tree plug-ins that can complete most common functions

  • Compatible with IE, FireFox, Chrome and other browsers
  • Multiple Tree instances can be generated simultaneously in one page
  • Support JSON data
  • Supports one-time static generation and Ajax asynchronous loading in two ways
  • Supports multiple event responses and feedback
  • Supports tree node movement, editing, and deletion
  • Supports any skin change/personalized icon (relying on css)
  • Supports extremely flexible checkbox or radio selection function
  • Simple parameter configuration to achieve flexible functions

Asynchronous loading means: when you click to expand the tree node, request the background action to return the child node data of the clicked node and load it.

Here we mainly design the async attribute setting of ztree’s setting variable:

var setting = {
  async: {
   enable: true,
   url:InitServiceIpsData.action,
   autoParam:[id, name],
   dataFilter: filter  
  },
 
Copy after login

When you click to expand the tree node, the action specified by the URL will be requested to obtain the child node data, and then bound to the ztree.

Note that the background action here returns a JSON string, and ztree only receives arrays when binding new node data, so you need to use the filter function to perform data cleaning and conversion operations before binding, and convert the string into an array:

//过滤异步加载ztree时返回的数据 
 function filter(treeId, parentNode, childNodes) {
  if (!childNodes) 
   return null;  
  childNodes = eval((+childNodes+)); //必须转换为[{id:103,pId:1,name:'子节点3'}];这样的格式 
  return childNodes;
 }
Copy after login

When you click to expand the ztree tree node, the action will be requested to obtain the child node data and bound.

The following is an implementation of background action:

public String InitServiceIpsData()
 {
  HttpServletRequest request = ServletActionContext.getRequest();
  String id = request.getParameter(id);
  String name = request.getParameter(name);
  System.out.println(请求获取+name+的ip列表);
   
  List<hashmap<string,object>> list = new ArrayList<hashmap<string,object>>();   
  for(int i = 1; i <= 2; i++){ 
   HashMap<string,object> hm = new HashMap<string,object>();   
   hm.put(id, id + 0 + i);
   hm.put(pId, id);
   hm.put(name, name + _IP_ + i);
   hm.put(isParent, false);
   list.add(hm);
  } 
   
  JSONArray finalJson = JSONArray.fromObject(list);
  this.initServiceIpsData = finalJson.toString();
  return SUCCESS;
 }</string,object></string,object></hashmap<string,object></hashmap<string,object>
 
Copy after login

The above are the detailed steps for implementing asynchronous loading operation of Jquery zTree tree control. I hope it will be helpful to everyone's learning.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
c# What is delegation and what problem does it solve? c# What is delegation and what problem does it solve? Apr 04, 2024 pm 12:42 PM

Delegation is a type-safe reference type used to pass method pointers between objects to solve asynchronous programming and event handling problems: Asynchronous programming: Delegation allows methods to be executed in different threads or processes, improving application responsiveness. Event handling: Delegates simplify event handling, allowing events such as clicks or mouse movements to be created and handled.

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to read html How to read html Apr 05, 2024 am 08:36 AM

Although HTML itself cannot read files, file reading can be achieved through the following methods: using JavaScript (XMLHttpRequest, fetch()); using server-side languages ​​(PHP, Node.js); using third-party libraries (jQuery.get() , axios, fs-extra).

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

Introduction to how to add new rows to a table using jQuery Introduction to how to add new rows to a table using jQuery Feb 29, 2024 am 08:12 AM

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:

How to optimize the performance of H5 page production How to optimize the performance of H5 page production Apr 06, 2025 am 06:24 AM

Through network requests, resource loading, JavaScript execution and rendering optimization, the performance of H5 pages can be improved and a smooth and efficient page can be created: resource optimization: compressed images (such as using tinypng), simplified code, and enabled browser caching. Network request optimization: merge files, use CDN, and load asynchronously. JavaScript optimization: reduce DOM operations, use requestAnimationFrame, and make good use of virtual DOM. Advanced skills: code segmentation, server-side rendering.

Sharing of PHP search function optimization tips Sharing of PHP search function optimization tips Mar 06, 2024 am 11:12 AM

PHP search function has always been a very important part of website development, because users often use the search box to find the information they need. However, many websites have problems such as low efficiency and inaccurate search results when implementing search functions. In order to help you optimize PHP search function, this article will share some tips and provide specific code examples. 1. Use full-text search engines. Traditional SQL databases are less efficient when processing large amounts of text content. Therefore, it is recommended to use full-text search engines, such as Elasticsearch, Solr, etc.

See all articles