Search code examples
event-handlingextjs3

EXTJS fireEvent


In the Ext.panel component, there is an event called expand(Ext.panel p).

Now I have 2 panels, A and B. The requirement is both of them should expand and collapse together. So when I expand A, i somehow need to fire the 'expand' event for B also. That should in turn fire the event handler for B. So the syntax (please help me with this):

A.on('expand', userPanelExpand)//event handler for A that performs some logic

Now how can I add a fireEvent('expand') for B? Should it read:

A.on('expand', userPanelExpand);
function userPanelExpand(){
//some logic
this.fireEvent('expand', this.B);
}

Something not right here.I get Stackvoerflow error at the last line.


Solution

  • A.on('expand', userPanelExpand, this);
    B.on('expand', userPanelExpand, this);
    
    // this will not go into recursion because if panel is already expanded then expand event will not be fired if we call panel.expand()
    function userPanelExpand(panel) {
       if(panel === A) {
          B.expand();
       } else {
          A.expand();
       }
    }