Pat*_*ice 1 javascript extjs window modal-dialog
我在我的页面标题上有一个首选项链接,它打开一个模态窗口(它用于修改用户首选项,如名称或密码).
在取消按钮我关闭此窗口,但当我尝试重新打开它时,我有这个JS错误:
el.addCls.apply(el, arguments);
Run Code Online (Sandbox Code Playgroud)
我是否使用关闭此窗口的好方法或问题是在其他地方?
这是我的代码:
// 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();
};
Run Code Online (Sandbox Code Playgroud)
您定义类的方式是在类的所有实例中创建和共享表单.当你第一次破坏窗口时,表单会随之被破坏,这就是它的结束.
相反,您应该:a)指定表单配置对象:
items: {
xtype: 'form',
// ....
}
Run Code Online (Sandbox Code Playgroud)
b)在initComponent方法中指定表单,使其绑定到该实例:
Ext.define('MyFoo', {
initComponent: function(){
this.items = new Ext.form.Panel(...);
this.callParent();
}
});
Run Code Online (Sandbox Code Playgroud)
小智 6
另一个可能解决您问题的解决方案是在窗口配置中指定closeAction:
closeAction: 'hide'
Run Code Online (Sandbox Code Playgroud)
有关closeAction的更多来自Extjs Docs:
单击关闭标题工具时要执行的操作:
可能的值:
Run Code Online (Sandbox Code Playgroud)'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.
Run Code Online (Sandbox Code Playgroud)
默认情况下,关闭操作值是destroy.