javascript 以编程方式在jstree中添加节点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29847867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:10:52  来源:igfitidea点击:

programmatically add Node in jstree

javascriptjstree

提问by Sunil Madan

I am trying to add a new node in jstreeprogrammatically on button click, as well as on contextmenucreate click, but there is some issue.

我试图jstree在单击按钮和contextmenu创建单击时以编程方式添加一个新节点,但存在一些问题。

Hereis the link of fiddle.

是小提琴的链接。

<div id="jstree">
  </div>
<button id="sam">create node</button>

回答by vakata

Here is your fiddle, fixed to work: http://jsfiddle.net/3q9Ma/223/

这是你的小提琴,固定工作:http: //jsfiddle.net/3q9Ma/223/

You were calling create_nodewith an array, which was wrong, also the string value 'null'was not the correct way to create a root node - use the special string value '#'(in later versions nullworks too, but not as a string).

您正在create_node使用数组调用,这是错误的,字符串值'null'也不是创建根节点的正确方法 - 使用特殊字符串值'#'(在更高版本中null也可以使用,但不能作为字符串)。

You might consider upgrading the jstree version - your fiddle was using a very early beta. Also keep in mind jstree itself does not require Angular.

您可能会考虑升级 jstree 版本 - 您的小提琴使用的是非常早期的测试版。还要记住 jstree 本身不需要 Angular。