How can I rename a jsTree node

前端 未结 3 1134
时光取名叫无心
时光取名叫无心 2021-02-18 22:09

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.

3条回答
  •  半阙折子戏
    2021-02-18 22:38

    The recommended method is to use rename_node

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

    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...
        }
    });
    

    Rename your node (alternative, not recommended)

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

    Debugging

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

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

    For older versions (v1.*)

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

    See also:

    • 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

提交回复
热议问题