简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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