2014-04-23 160 views
1

我設置的聽衆似乎沒有觸發。這裏是我的代碼:ExtJs Tabpanel關閉事件與關閉標籤

new Ext.TabPanel({ 
     id:'content-tab-panel', 
     renderTo: 'trx_tabs_ext', 
     activeTab: 0, 
     minTabWidth: 150, 
     tabWidth:180, 
     enableTabScroll: true, 
     autoScroll: true, 
     resizeTabs:true, 
     defaults: { 
      autoScroll:true 
     }, 
     items: [{ 
      title: 'No Active Chat', 
      id: 'no_chat', 
      closable: true, 
      autoScroll: false, 
      margins: '0 0 0 0', 
      html: "<div id=\"chat_window_viewer\" style=\"width:900px;height:440px;text-align:left; \">&nbsp;</div>" 
     }], 
     width: '100%', 
     height: '400px', 
     listeners: { 
      tabchange: function(tabPanel, newTab, oldTab, index) 
      { 
       console.log('change tab'); 
      }, 
      beforeadd : function (tabpane, component, index) { 
       console.log('Adding new tab'); 
      }, 
      beforeclose: function(element) { 
       console.log('closing'); 
      } 
     } 
    }); 

之前添加了tabchange觸發器,並通過在控制檯寫入日誌來實現。但是,beforeclose不會。

我也試過把它放在Tabpanel的內部,也不起作用。

什麼是在TabPanel中添加關閉事件的正確方法?

回答

0

哪個庫的版本使用的是?請注意,自2.3.0以來可用的beforclose事件。

這對我的作品時,我的項目監聽事件,而不是整個面板

new Ext.TabPanel({ 
     id:'content-tab-panel', 
     renderTo: 'trx_tabs_ext', 
     activeTab: 0, 
     minTabWidth: 150, 
     tabWidth:180, 
     enableTabScroll: true, 
     autoScroll: true, 
     resizeTabs:true, 
     defaults: { 
      autoScroll:true 
     }, 
     items: [{ 
      title: 'No Active Chat', 
      id: 'no_chat', 
      closable: true, 
      autoScroll: false, 
      margins: '0 0 0 0', 
      html: "<div id=\"chat_window_viewer\" style=\"width:900px;height:440px;text-align:left; \">&nbsp;</div>", 
      listeners:{ 
       'beforeclose': function(){console.log('closed')} 
      } 
     }], 
     width: '100%', 
     height: '400px', 
     listeners: { 
      tabchange: function(tabPanel, newTab, oldTab, index) 
      { 
       console.log('change tab'); 
      }, 
      beforeadd : function (tabpane, component, index) { 
       console.log('Adding new tab'); 
      } 
     } 
    }); 
+0

其ExtJS的2.2。是的,它是一隻恐龍。我一直想升級但沒有時間。你有沒有參數的項目中的聽衆?有用? – oneofakind

+0

恐怕在2.3.0之前關閉事件。 ExtJS是JavaScript框架,因此它遵循JavaScript規則。如果你不需要參數 - 不要發送它。 –

+0

*馬里奧去世音樂*就是這樣,它的升級時間。 – oneofakind

0

由於ExtJS的2.3.0tabpanel■找一個beforeclose事件:

beforeremove (this,component,eOpts)

之前的任何火災Ext.Component已從容器中移除。處理程序可以返回false來取消刪除 。

推介因爲:2.3.0

參數

  • 此:Ext.container.Container
  • 組分:Ext.Component 組件被移除
  • eOpts:Object選項對象傳遞到 Ext.util.Observable.addListener

所以只需添加在您的tabpanel監聽器:

listeners: { 

    beforeremove: function (panel, item, eOpts) { 
     console.log(item); // the tab to be removed 
    } 
. . . . 
}