tags:

views:

64

answers:

1

Hi all

I've created an extJs drag and drop tree and I'm attemting to check whether a node exists in a particular branch before it's dropped in. To do this, I'm overwriting a method called beforeDragDrop() (Link), which passes in the whole Target tree, the Event object, and the Dragged item ID.

Calling Event.getTarget() gives me the the target node of the item adjacent to the dropped item. What I really need is the parent node within the target where this item is dropped, which will allow me to check whether the item already exists within the branch.

Is there any way of getting the id of a Tree branch within the drop target in ExtJs?

It's a long shot, but I've been faffing around for ages and could really do with a hand.

Thanks!

+1  A: 

Is there a parent() method for the target node? What kind of object does getTarget() return?

Kenny Peng
getTarget() returns the HTML element of the node, for example <div id='123' ext:tree-node-id='2010'>Item</div>. The problem is amplified by the fact the id I need is the one generated automatically by ExtJs - ext:tree-node-id, and I can't fathom how to get access to that property - it seems to be created by the JSONLoader when the tree is created.
Alan Grant
In the documentation for `Ext.EventObject`, it seems like `getTarget()`'s third parameter is a boolean that specifies whether it should return an `Ext.Element`. `Ext.EventObject` is a Static class though, so I don't know if it has the same methods as `Event`, but if the same parameter exists for `Event`, then with the `Ext.Element` you get back, you can call `parent()`.
Kenny Peng
Ah nicely done, having the object is exactly what I had wanted. For some reason calling parent() just returns the same node. Have I missed a trick?
Alan Grant
Not sure why `parent()` isn't doing what you want, I would try `up()` with a empty selector to see if it gives different results.
Kenny Peng