venkatanagaraju / dynatree

Automatically exported from code.google.com/p/dynatree
0 stars 0 forks source link

Read auto allocated node key after drop #444

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Regarding node DND: When a node drop is complete I need to access the unique 
key value automatically assigned to the dropped node in the target tree. 
I note that the key value is available on the onDrop event as it turns up in 
the following:
var dict = $("#tree2").dynatree("getTree").toDict();
alert("Sending: " + JSON.stringify(dict));

I can't find an answer to this question in any of the forums. Is this because 
it is not yet a feature?

Original issue reported on code.google.com by leschamb...@gmail.com on 17 Jul 2013 at 2:10

GoogleCodeExporter commented 9 years ago
Hi. I solved my problem with this code (as part of the onDrop event) but it 
seems like a bit of a cluge. Is there a better way?

onDrop: function(node, sourceNode, hitMode, ui, draggable) {
    /**This function MUST be defined to enable dropping of items on the tree.
     * sourceNode may be null, if it is a non-Dynatree droppable.
     */
// ...

// Find the dropped node's parent and get the parent's key
//
if (hitMode == "over") {
// The dropped node was dropped on this node so this node IS the parent
var droppedNodeParentKey = node.data.key; 
} else {
// The dropped node was dropped either before or after the node.
// The dropped node is therefore a sibling of node so:
// the dropped node's parent is node's parent
var droppedNodeParent = node.getParent();  // get the sibling's parent
var droppedNodeParentKey = droppedNodeParent.data.key;
        }

alert("Parent key: " + droppedNodeParentKey);

}

Original comment by leschamb...@gmail.com on 17 Jul 2013 at 2:59

GoogleCodeExporter commented 9 years ago
To clarify: This solution worked for me because I actually needed the parent 
key to populate a relational database. This method would not get the dropped 
node key if the node was dropped with hit mode "over" on a node that had 
children. You wouldn't know which of the children had just been dropped. So I 
guess the problem still remains.

Original comment by leschamb...@gmail.com on 17 Jul 2013 at 3:07

GoogleCodeExporter commented 9 years ago
Just curious: if the keys are important to you, why don't you assign them 
yourself instead of letting dynatree generate arbitrary ones?

Original comment by moo...@wwwendt.de on 20 Jul 2013 at 3:05

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 8 Sep 2013 at 6:47