2010-12-20 129 views
5

有沒有辦法將OnClick事件附加到EXTJS中的選項卡開關?EXTJS OnClick選項卡事件

我使電網這樣的:

var simple = new Ext.FormPanel({ 
    labelWidth: '100%', 
    border:false, 
    width: '100%', 
      style: 
      { 
       height: '291px' 
      }, 
    items: { 
     xtype: 'tabpanel', 
     activeTab: 0, 
     //labelWidth: 75, // label settings here cascade unless overridden 
     items:[{ 
     url:'save-form.php', 
     title: 'Tab 1', 
    ... 

謝謝!

回答

7

我在聽衆中添加的標籤後是這樣定義的:

//define all tabs, and after the ] from the tab panel JSON: 
listeners: { 
    'tabchange': function(tabPanel, tab) { 
     alert("tab changed"); 
    } 
} 

這只是警告當標籤改變,這對我的目的來說已經足夠了。我不確定如何找出哪個標籤是當前標籤。

希望這可以幫助未來的人。

+4

'Ext.TabPanel.getActiveTab()'返回作爲活動選項卡的組件。 – Mchl 2010-12-20 17:41:29

+2

您的tabchange eventhandler中的第二個參數將是對激活選項卡的引用。 – HOCA 2010-12-22 01:36:15

0
There is no event for tab click in TabPanel, however you can bind into click event on each tab. You can add custom event. 
Following example help to you. 


{ 
    xtype : 'tabpanel', 
    items : [{ 
    xtype : 'panel', 
    title: 'ABC' 
    },{ 
     xtype : 'panel', 
     title : 'XYZ' 
}], 
    listeners: { 
    render: function() { 
    this.items.each(function(panel){ 
     // Added tabclick event for tabpanel                   
     panel.tab.on('click', function(){ 
     panel.addEvents('tabclick'); // addded event to panel 
     panel.fireEvent('tabclick', panel); 
     }); 
     }); 
     } 
    } 
     }