edit node after creation in jstree jquery plugin

I have a button that by click it, a new node was created for current selected node.

in addition I want this newly node get edit state to faster edit capability.

this is code that I wrote :

    $('#add-node').click(function () {
    currentNode     =   $treeview.jstree("get_selected");
    $treeview.jstree('create_node', currentNode, {text : "salam"}, 'last' , function(new_node){
        $treeview.jstree("open_node", currentNode);
        setTimeout(function () {
            $treeview.jstree('rename_node', new_node);
        }, 0);
    });
});

But this doesn't work , node creates but could not rename it immediately.

Answers 1

  • I found the solution:

        $('#add-node').click(function () {
        currentNode     =   $treeview.jstree("get_selected");
        $treeview.jstree('create_node', currentNode, {text : "new Node"}, 'last' , function(new_node){
            $treeview.jstree("open_node", currentNode);
            var inst = $.jstree.reference(new_node);
            inst.edit(new_node);
        });
    });
    

    just sould get a reference to newly created node then edit it .


Related Articles