Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize zTree search in jQuery

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to achieve zTree search in jQuery". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

About Tree Node

To complete the various methods in the above process, we need to know a series of attributes of the tree node. We all know that there is an artifact like api. However, a feature of api is that it is complete (it may be easy to find an attribute or method when we want to find an attribute or method accurately). What we want here is how to quickly get the attributes or methods we want. We print out a collection of tree nodes on the console:

Var treeObj=$.fn.zTree.getZTreeObj ("homeTree"); / / set root node var node = treeObj.getNodes (); / / get root node var nodes = treeObj.transformToArray (node); / / get all nodes console.log (nodes)

Look at the picture: we can see all the nodes, including various attributes such as id,name

Look at the figure again: we can see the various attributes of any node, including the collection of child nodes we want childern, the parent node attribute isParent, the node id tId, and the parent node id parentTid....

Everything is ready. Do it.

Let's take a look at the relevant methods. Many small details need to be found in the real coding process. Here we enumerate the methods directly for the convenience of demonstration.

Declare an alternate array:

/ / region search var parentArray = []; var childArray = []

Recursively get the parent node collection of the target node:

/ / Recursively get all parent nodes of the target node function getParentsNode (treeNode) {var thisParentNode = treeNode.getParentNode (); / / get the parent node if (thisParentNode! = null) {/ / parent node exists parentArray.push (thisParentNode); / / save to array getParentsNode (thisParentNode); / / reset} else {return false;}}

Recursively get the collection of target node children:

/ / Recursively get all the children of the target node function getChildrenNode (treeNode) {var thisIsParent = treeNode.isParent; / / get the isParent attribute of the target node, and determine whether it is the parent node if (thisIsParent = = true) {var thisChildrenNode = treeNode.children; / / get the set of child nodes of the node for (var inode

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report