How to move full node (parent and children) from one tree to another by selecting parent node in JSTree?

Viewed 89

I am a novice to jQuery and jstree. Kindly correct my code. No solution is working for me from its docs. I want to select one parent node and create this complete node (parent and children) to another tree. For this, I have created the following code:

// Moving nodes on click event
     $(MoveButton).on('click', function() {

        var parent = $(TreeContainer).jstree("get_selected", true); // to get selected parent node
        var childrens = $(TreeContainer).jstree("get_childrens_dom", true); // to get all the children of the parent
        var newNode = { text: $(TreeContainer).jstree("get_selected", true)[0].text }; //to get text of selected parent node

        for(let i = 0; i < childrens.length; i++) {

            $(NextTree).jstree(true).create_node(parent, newNode); // creating the selected node in next tree
            parent = $(TreeContainer).jstree("get_next_dom", true); // to get the next node of the parent
            newNode = { text: $(TreeContainer).jstree("get_next_dom", true)[0].text } ; // to get the text of next node of parent
        }

 }

0 Answers
Related