PDA

View Full Version : how to find the current tree node



chadsteele
4 Mar 2008, 11:39 AM
Hello,
This is my first post. I am very, very impressed with extjs and this community. Thank you.

I often need to find the selected node (or the root node) when using a tree, so I made this little function an attribute of the panel. Is this a good method? If so, I hope it is useful to others.



var tree = new Ext.tree.TreePanel({
.
.
.
current: function()
{
var n = this.getSelectionModel().getSelectedNode();
if (!n) n = this.root;
return n;
}
})

evant
4 Mar 2008, 2:51 PM
Sure, you could shorten it though:



current: function()
{
return (this.getSelectionModel().getSelectedNode() || this.root);
}