簡體   English   中英

Extjs:銷毀並重新打開模態窗口

[英]Extjs : destroy and reopen modal window

我的頁面標題上有一個首選項鏈接,該鏈接打開一個模式窗口(用於修改用戶首選項,如名稱或密碼)。

在“取消”按鈕上,我關閉了此窗口,但是當我嘗試重新打開它時,出現了JS錯誤:

el.addCls.apply(el, arguments);

我是使用關閉此窗口的好方法還是問題出在其他地方?

這是我的代碼:

// My window definition
Ext.define('jnotes.window.UserPreferences', {
    extend: 'Ext.window.Window',
    layout: 'fit',
    modal: true,
    renderTo: Ext.getBody(),
    title: "<s:text name='user.preferences' />",
    items: new Ext.form.Panel({
        bodyPadding: 5,
        waitMsgTarget: true,
        method: 'POST',

        fieldDefaults: {
            labelAlign: 'right',
            labelWidth: 85,
            msgTarget: 'side'
        },
        defaultType: 'textfield',
        items: [{
            ... // my fields
        }],
        buttons: [{
            text: "<s:text name='action.save'/>",
            handler: function() {
                this.up('form').fireEvent('validate');
            },
        }, {
            text: "<s:text name='action.cancel'/>",
            handler: function() {
                this.up('form').fireEvent('cancel');
            }
        }]
    })
});

var preferencesWindow = null;

// Open my window
function displayPreferences() {
    preferencesWindow = Ext.create('jnotes.window.UserPreferences');
    var form = preferencesWindow.down('form');
    form.addListener('validate', this.saveUser, this);
    form.addListener('cancel', function() {
        preferencesWindow.close();
        preferencesWindow = null;
    }, this);
    form.load({
        ... // Loading data
    });
    preferencesWindow.show();
};

定義類的方式將創建該表單,並在該類的所有實例之間共享表單。 第一次銷毀窗口時,表單會隨之銷毀,這就是結束了。

相反,您應該:a)指定一個表單配置對象:

items: {
    xtype: 'form',
    // ....
}

b)在initComponent方法中指定表單,以便將其綁定到該實例:

Ext.define('MyFoo', {
    initComponent: function(){
        this.items = new Ext.form.Panel(...);
        this.callParent();
    }
});

可能解決您問題的另一種解決方案是在窗口配置中指定closeAction:

closeAction: 'hide'

來自Extjs Docs的有關closeAction的更多信息:

單擊關閉標題工具時要執行的操作:

可能的值:

 'destroy' : remove the window from the DOM and destroy it and all descendant Components. The window will not be available to be redisplayed via the show method. 
'hide' : hide the window by setting visibility to hidden and applying negative offsets. The window will be available to be redisplayed via the show method.

默認情況下,關閉操作值是destroy。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM