jstreejstree-dnd

Cant retrieve new parent id in the paste event, for Copy/ Paste functionality in jstree


I am trying to implement copy / paste functionality on my folders in jstree. The problem is that, in the paste event when i access the parent id, it gives me the id of the old parent node of the folder. I need the new parent_id of the node where the folder is pasted to. When i implement a cut event followed by a paste event, I am able to get the new parent_id by retrieving it in the paste event, but unfortunately I am not able to get the same for copy/paste . How can I get new parent_id ? Please let me know. Thank you. I appreciate your help! The log statements in the code is as follows:

.on('copy_node.jstree', function (e, data) {  
    console.log(" copy event ");
    console.log(" type : "+data.node.type);
    console.log(" id : "+data.node.id);
    console.log(" text : "+data.node.text);
    console.log(" new parent id  : "+data.node.parent)  
}).on('paste.jstree', function (e, data) {  
    console.log(" paste event ");
    console.log(" parent id : "+data.node[0].parent);
    console.log("  parents id  : "+data.node[0].parents);
    console.log("  tree node id  : "+data.node[0].id);
    console.log(" type : "+data.node[0].type);
})

The output seen is as follows:
copy event 
type : default
id : j1_5
text : New node
new parent id  : j1_2
paste event 
parent id : j1_1
parents id  : j1_1,#
tree node id  : j1_4
type : default

Please NOTE: I am getting new parent_id in the copy event i.e 'j1_2' but I am unable to get it in the paste event. I want this new parent_id in order to persist in the db. The paste event shows parent_id as 'j1_1' which is the old parent_id of the copied node.


Solution

  • data.parent gives me the new parent node id.