2011-09-30 30 views
2

我想破坏标签面板的内容,因为当我再次打开面板时,它仍然是之前的内容。所以它显示2个相同的内容。Extjs,如何删除标签面板的内容

所以我想把代码销毁标签面板内容到beforeclose事件处理程序。

,我试图这样,

tempTab.on('beforeclose',function(obj){ 
     this.items.each(function(c){this.remove(c)}); 
}); 

,但它不工作。

任何人都可以帮忙吗?

源:

ManuBar区(MENU)

menubar.add({ 
    text : 'Administrator', 
    iconCls : 'plugin', 
    menu : { 
    items : [ 
     { 
     text : 'Menu Management', 
     id : 'menuManagement', 
     iconCls : 'tabs', 
     url : 'main/test2', 
     handler : onMenuClick 
     },{ 
     text : 'User Management', 
     id : 'useManagement', 
     iconCls: 'user', 
     url : 'main/test', 
     handler : onMenuClick 
     }] 
    } 
}) 

马努处理程序

function onMenuClick(item) { 

    if(!Ext.getCmp('tab_'+item.id)){ 
    var tempTab = Ext.getCmp('mainTabPanel').add({ 
     id : 'tab_'+item.id, 
     margins : '0 5 5 0', 
     deferredRender : false, 
     closable : true, 
     title : item.text, 
     plain : true, // 
     defaults : {autoScroll : true}, 
     autoLoad : { 
     url : '/ext/main/test2/', 
     scripts : true 
     }, 
     listeners : { 
     'beforeclose' : function(){ 
      alert(this.items.get(0).id); // output : testPanel 
      this.removeAll(); 
       alert(this.items.get(0).id); // output : undefined 
     } 
     } 
    }); 

    tempTab.on('beforeclose',function(){ 
     //console.log(this); 
     this.removeAll(); //////////////////////////////////// 
    }); 
    Ext.getCmp('mainTabPanel').setActiveTab(tempTab); 

    }else { 
    var tempTab = Ext.getCmp('tab_'+item.id); 
    Ext.getCmp('mainTabPanel').setActiveTab(tempTab); 
    } 
} 

和内容(test2.php)(其加载使用自动加载和脚本:true)

test = function(){ 
return { 
    init : function() { 
    Ext.QuickTips.init(); 
    var app = new Ext.Panel({ 
     id : 'testPanel', 
     html : 'My Second Panel' 
    }); 

    var tab = Ext.getCmp('tab_menuManagement'); 
    //app.relayEvents(tab, ['activate', 'deactivate', 'beforeclose']); 
    tab.add(app); 
    tab.doLayout(); 

    tab = null; app = null; 
    } 
} 
}(); 


Ext.onReady(test.init, test, true); 

我认为该项目成功删除。但仍然在关闭并再次打开选项卡时。 它显示2个相同的内容。

我的第二面板 我的第二面板

我不知道什么是错....

---更新---

我改变了test2.php文件中像这

var tab = Ext.getCmp('tab_menuManagement'); 
tab.removeAll(); // I added 
tab.add(app); 
tab.doLayout(); 

然后它的工作。有点奇怪。在关闭之前,它被删除。但如何 它再次活着.... ??任何人帮助?

谢谢!

回答

2

尝试

tempTab.on('beforeclose',function(obj){ 
    this.removeAll(); 
}); 

注:

removeAll([Boolean autoDestroy]) : Array 
*Removes all components from this container*. 
+2

我只是试过,但它不工作.. –

+0

分享更多的来源.. – TheHorse

+0

好吧,我会编辑我的问题。请给我5分钟!谢谢! –

1

您使用的是一些不好的做法。例如:

variabile.on('event', handler, scope) 

这会让variable活着,因为有非托管的事件(由分机不受管理的,因为它是由您管理)。如果您手动收听活动,则必须在销毁variable之前将其卸载。或者如果你像我一样(懒惰:-)只需使用this.mon

另一个坏事是Ext.getCmp(和id) - 它应该只用于调试目的,而不是用于开发。当我开始使用Ext时,我使用了id,并且在创建TabPanel的多个实例时,我有非常奇怪的问题。