简体   繁体   中英

Get node by Id in jstree

I have ids and I need to get the corresponding nodes.

But how ?

Here, "n" is my node id. How can i get the jstree object?

$.each(data.node.children,function(k,v){
 var n = $("#jstree_demo_div").find("[id='"+v+"']");
 console.log(n);
});

Regards.

To get the reference to the DOMElement you just need to call .get(0) on the jQuery object.

$.each(data.node.children,function(k,v){
 var n = $("#jstree_demo_div").find("[id='"+v+"']").get(0);
 console.log(n);
});

Unless you are working with invalid html, this can be shortened to the following:

$.each(data.node.children,function(k,v){
 var n = $('#'+v).get(0);
 console.log(n);
});

Solved.

I didn't have to get the node by id.

I get the JSON of the parent and find children.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM