PDA

View Full Version : treenode/tree question



kyriakos
5 Feb 2007, 3:37 AM
I'm trying to make a tree that only allows a limited number of depth levels. In my case up to three. I handle the beforenodedrop event but in order the cancel the drop i must know which depth level the target treenode is at. Is there any way of doing that?

jack.slocum
5 Feb 2007, 5:05 AM
This is in the dev code. You can add it anywhere after yui-ext.js:


/**
* Returns depth of this node (the root node has a depth of 0)
* @return {Number}
*/
Ext.data.Node.prototype.getDepth = function(){
var depth = 0;
var p = this;
while(p.parentNode){
++depth;
p = p.parentNode;
}
return depth;
};

kyriakos
5 Feb 2007, 5:29 AM
thanks jack! :)