Hybrid View

  1. #1
    Ext User sosamv's Avatar
    Join Date
    Apr 2009
    Posts
    81
    Vote Rating
    0
    sosamv is on a distinguished road

      0  

    Default Unanswered: Extjs Core cuestion

    Unanswered: Extjs Core cuestion


    Hi! I need to add the click event for each element of the CompositeElement and toggle its own class.


    Code:
    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!

  2. #2
    Ext User sosamv's Avatar
    Join Date
    Apr 2009
    Posts
    81
    Vote Rating
    0
    sosamv is on a distinguished road

      0  

    Default FIXED

    FIXED


    Got it working :S

    Code:
    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?

  3. #3
    Touch Premium Member letssurf's Avatar
    Join Date
    Jan 2008
    Location
    Northampton, UK
    Posts
    88
    Vote Rating
    1
    letssurf is on a distinguished road

      0  

    Default


    It might also be a good idea to use one click handler and use the delegate option.

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

    the one constant in life, is change.

  4. #4
    Ext User sosamv's Avatar
    Join Date
    Apr 2009
    Posts
    81
    Vote Rating
    0
    sosamv is on a distinguished road

      0  

    Default Thanx!

    Thanx!


    Didnt know about that!, thanx!

Thread Participants: 1