Home > Article > Web Front-end > Ztree method to obtain the child node id collection of the currently selected node_javascript skills
The example in this article describes how ztree obtains the set of child node ids of the currently selected node. Share it with everyone for your reference. The specific analysis is as follows:
Requirements: Get the set of child node ids of the currently selected node.
Steps:
1. Get the current node
2. Use the ztree method transformToArray() to obtain the collection of child node objects of the currently selected node (including the selected node).
3. Traverse the collection and retrieve the required values.
treeNode: currently selected node object
function getChildNodes(treeNode) { var childNodes = ztree.transformToArray(treeNode); var nodes = new Array(); for(i = 0; i < childNodes.length; i++) { nodes[i] = childNodes[i].id; } return nodes.join(","); }
I hope this article will be helpful to everyone’s JavaScript programming design.