PDA

View Full Version : firing click event on a tree node



pirusira
18 Jul 2010, 6:45 PM
Hello all,

The following is the treepanel and nodes.


var menuTP = new Tree.TreePanel({
loader: new Tree.TreeLoader()
});
var root = new Tree.TreeNode({
text: 'root',
});
menuTP.setRootNode(root);

var menu = [{
"text": "m1",
"id": "m2",
"depth": "0",
"leaf": true,
},{
"text": "m2",
"id": "m2",
"depth": "0",
"leaf": true,
}];
for (var i = 0, len = menu.length; i < len; i++) {
root.appendChild(menuTP.getLoader().createNode(menu[i]));
}


I attempted the following to fire click event.

menuTP.getNodeById('m1').fireEvent('click');

But it showed me this error : 'node is undefined'

The event is supposed to do this.


menuTP.on('click', function(node){
if(node.isLeaf()){ //<--this is the error line.
handleMenuEvent(node);
}
});


How can I fire the event with the node parameter?

Thanks in advance.
Stan

Animal
18 Jul 2010, 9:12 PM
Duh! So, pass the node!

Condor
18 Jul 2010, 10:07 PM
var node = menuTP.getNodeById('m1');
node.fireEvent('click', node);

ps. Firering a click event doesn't select or focus the node. You'll have to do that yourself.