2011-09-30 69 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的多個實例時,我有非常奇怪的問題。