简体   繁体   English

在jstree中按ID获取节点

[英]Get node by Id in jstree

I have ids and I need to get the corresponding nodes. 我有ID,需要获取相应的节点。

But how ? 但是如何?

Here, "n" is my node id. 在这里,“ n”是我的节点ID。 How can i get the jstree object? 如何获取jstree对象?

$.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. 要获取对DOMElement的引用,您只需要在jQuery对象上调用.get(0)

$.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: 除非使用无效的html,否则可以将其缩短为以下内容:

$.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. 我不必按ID来获取节点。

I get the JSON of the parent and find children. 我得到父级的JSON并找到子级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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