2012-04-09 50 views
2

在Ext.panel組件中,有一個名爲expand的事件(Ext.panel p)。EXTJS fireEvent

現在我有2個面板,A和B.要求是他們兩個應該一起展開和摺疊。所以當我擴展A時,我也需要爲B發起'擴展'事件。這應該又火B. 事件處理程序所以語法(請幫我這個):

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

現在,我怎麼添加fireEvent(「擴大」)對於B?它應該是:

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

有些東西不對,我在最後一行出現Stackvoerflow錯誤。

回答

1
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(); 
    } 
} 
相關問題