Ztree Gets an example of the ID of the first child node and all the node IDs

Source: Internet
Author: User
Tags function examples json

Ztree.getselectednodes () [0] is the first node to get the selected

Getnodebytid

overview [dependent Jquery.ztree.core core JS]

Quickly get a node JSON data object based on Ztree unique identification tId

Through the internal cache acquisition, do not need to traverse the node.

Please execute this method through the Ztree object.

Function parameter Description

Tidstring

Unique identification of the node within the Ztree tId

return value JSON

TId the corresponding node JSON data object

Null if no result is returned

function examples

1. Get the node data for tId = "Tree_10"

The code is as follows Copy Code

var treeobj = $.fn.ztree.getztreeobj ("tree");
var node = Treeobj.getnodebytid ("tree_10");

Get the first one is:

var node = Treeobj.getnodebytid ("Tree_1");

Gets all child node IDs under the current node

The code is as follows Copy Code

var setting = {

Data: {

Simpledata: {

enable:true

}

},

View: {

Showicon:false

p>},

callback:{

Onclick:function ztreeonclick (event, Treeid, TreeNode) {

Alert (Treenode.tid + "," + Treenode.name+ "," +treeid);

Var ids=[];

Ids=getchildren (Ids,treenode);

  

}

 

 

},

Check: {

Enable:true,

Autochecktrigger:false,

chkboxtype:{"Y": "PS", "N": "PS"}

}

 

};

 

//ids is an array that returns an array of results TreeNode is the selected node

Function GetChildren (ids,treenode) {

Ids.push (treenode.id);

 if (treenode.isparent) {

for (Var obj in Treenode.children) {

GetChildren (ids,treenode.children[ OBJ]);

}

}

 return IDs;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.