PDA

View Full Version : Extjs Core cuestion



sosamv
10 Jul 2009, 9:32 AM
Hi! I need to add the click event for each element of the CompositeElement and toggle its own class.




arr = Ext.select('.cMenuParentCollapsed');

arr.each(function(){
this.on("click",function(e,t){
this.toggleClass("cMenuParentExpanded");
});
});
when i do this, i can click on any item but it will only toggle the last item :S
What i'm i doing wrong?

Thanx!

sosamv
10 Jul 2009, 9:41 AM
Got it working :S



arr = Ext.select('.cMenuParentCollapsed');

arr.each(function(){
this.on("click",function(evnt,html){
Ext.get(html).toggleClass("cMenuParentExpanded");
});
});


Is this the best way to do it?

letssurf
11 Jul 2009, 7:39 AM
It might also be a good idea to use one click handler and use the delegate option.

Something like.


var handler = function(evnt, html){
Ext.get(html).toggleClass("cMenuParentExpanded");
};
Ext.getBody().on('click', handler, scope, {delegate: '.cMenuParentCollapsed'})

sosamv
11 Jul 2009, 10:54 AM
Didnt know about that!, thanx!