2012-02-23 100 views
1

我正在使用ExtJs4。銷燬窗口

new Ext.Window({ 
    id: token + '_window', 
    animateTarget: token + '_taskbar', //Button id 
    height: 300, 
    width: 300, 
    title: name, 
    maximizable: true, 
    minimizable: true, 
    iconCls: 'basketball-small-icon', 
    html: 'This is the <b>' + name + '</b> window', 
    listeners: { 
     'beforeclose': onWindowClose, 
     'minimize': function(){ this.hide(); } 
    } 

請注意與動畫目標關聯的按鈕。 這裏onWindowClose被定義爲

function onWindowClose(t){ 
var token = t.id.split('_')[0]; 
var taskBarItemId = token + '_taskbar'; 

Ext.getCmp(taskBarItemId).destroy(); //Destroying the button 
t.destroy(); //Destroying the window 
} 

在這裏,我想刪除的窗口和相關的按鈕。 每次我關閉窗口,我有兩個選擇,如下

  • 我可以摧毀兩個按鈕和窗口,但有時我不能再打開窗口。我認爲這與該按鈕鏈接到窗口的'animateTarget'這一事實有關。因爲當我刪除這個屬性,這工作正常。
  • 我可以使用t.close()而不是t.destroy(),但它會變成遞歸的。我如何調用基本關閉方法?

是否每次銷燬窗口並在每次單擊圖標時使用'new'創建一個好主意? close()和destroy()方法有什麼區別?

回答

0

您不必調用destroy(),因爲一旦窗口關閉,它就會自動銷燬。
查看Ext.Window的api。
並且不要在beforeclose處理程序中調用close(),因爲它已經快要關閉了。

我想你可以使用'new'來創建一個窗口並關閉它,或者點擊close header工具(右上角)或者調用close()方法。不要擔心摧毀。分機將做到這一點。

close()和destroy()之間的主要區別是關閉fire's beforeclose'事件並根據配置選項'closeAction'決定是關閉窗口還是隱藏窗口。如果它決定關閉,destroy()將被調用。

編輯: 嘗試以下

function onWindowClose(t){ 
    var token = t.id.split('_')[0]; 
    var taskBarItemId = token + '_taskbar'; 

    Ext.getCmp(taskBarItemId).destroy(); //Destroying the button 
    //t.destroy(); //Remove this statement. 
    return true; 
} 

EDIT2:刪除減少聽者

listeners: { 
    'beforeclose': onWindowClose//, 
    //'minimize': function(){ this.hide(); } 
} 
+0

你要我不包括t.close()或t.destroy()。 – Shashwat 2012-02-23 12:37:27

+0

@Shashwat不要點擊右上角的'x'按鈕關閉窗口?那麼是的,你不需要調用close()或destroy()。 – 2012-02-23 12:47:16

+0

你想讓我不要包含t.close()或t.destroy()嗎?這是行不通的。它刪除按鈕,但不是窗口和窗口卡住。 我認爲t。如果我在處理程序中調用基本方法close(),close()將被觸發。你能告訴我該怎麼做嗎? – Shashwat 2012-02-23 13:03:56

2

如果我沒有理解好了,你想重用的窗口,具有不同的內容。 因此,您應該只創建一個窗口,通過更新html內容並在此窗口中調用show()來重用。 要執行該操作,您需要添加屬性closeAction:'hide'。這樣,當你點擊關閉按鈕時,你的窗口不會被破壞。

test = new Ext.Window({ 
    id: token + '_window', 
    animateTarget: token + '_taskbar', 
    height: 300, 
    width: 300, 
    title: name, 
    maximizable: true, 
    minimizable: true, 
    closeAction: 'hide', 
    iconCls: 'basketball-small-icon', 
    html: 'This is the <b> imad </b> window', 
    listeners:{ 
     'beforehide':function(win){ 
      Ext.getCmp(win.animateTarget).hide(); 
     } 
    } 
}); 

然後,這個監聽器添加到您的按鈕:

listeners:{ 
     'click':function(){ 
      var token = t.id.split('_')[0]; 
      var targetWindow = Ext.getCmp('token + '_window); 
      targetWindow.body.dom.innerHtml = 'Your new html !'; 
      targetWindow.show(); 
     } 
    }