如何重命名jsTree节点 [英] How can I rename a jsTree node

查看:765
本文介绍了如何重命名jsTree节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是在谈论 $(#demo1)。jstree(rename,node)这使得节点可以为用户编辑。我在谈论代码中正在更改的名称。例如,在我调用 $(#demo1)之前,我的节点都以2位数字[01]作为前缀.jstree(rename,node)我想删除前缀,并在用户完成编辑后将其重新放入。我已经尝试选择#nodeid a,但在超链接中有一个ins标签,如果我替换URL内容,这将被替换。文档没有帮助,我没有看到图书馆代码的运气,可以帮助我吗? Chris

I am not talking about $("#demo1").jstree("rename",node) which makes the node editable for the user. I am talking about the name being changed within the code. For example my nodes are all prefixed with a 2 digit number "[01]" so before I call $("#demo1").jstree("rename",node) I want to strip out the prefix, and put it back in once the user has finished editing. I have tried selecting "#nodeid a" but inside the hyperlink there is an ins tag and this gets replaced if i replace the URL contents. The documentation hasn't been helpful and I havent had much luck looking through the libraries code, can any help me? Chris

推荐答案

推荐方法是使用 rename_node

The recommended method is to use rename_node

$("#demo1").jstree('rename_node', node , text );




请记住 默认情况下对树的所有修改都是
阻止
(创建,重命名,移动,删除) 。要启用它们,请将
core.check_callback 设置为true

Please keep in mind that by default all modifications to the tree are prevented (create, rename, move, delete). To enable them set core.check_callback to true



$('#demo1').jstree({
    'core': {
        'check_callback': true,
        /// rest of the options...
    }
});

重命名您的节点(替代方案,不推荐)

$("#demo1").jstree('set_text', node , text );

调试

如果您仍然遇到问题,可以使用此方法获取上一个错误。

If you still encounter trouble, you can use this method to get the last error.

$('#demo1').jstree(true).last_error()

旧版本(v1。*)

$("#demo1").jstree('rename_node', [node , text] ); 
$("#demo1").jstree('set_text', [node , text] ); 

参见:

  • this jsfiddle for the comparison and example of both methods.
  • Interaction with jsTree (how to call API methods)
  • API documentation of rename_node
  • API documentation of set_text

这篇关于如何重命名jsTree节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆