2014-04-23 39 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 
    } 
. . . . 
}