Javascript Extjs:销毁并重新打开模式窗口
我的页面标题上有一个首选项链接,可以打开一个模式窗口(用于修改用户的首选项,如名称或密码) 在“取消”按钮上,我关闭此窗口,但当我尝试重新打开它时,出现以下JS错误:Javascript Extjs:销毁并重新打开模式窗口,javascript,extjs,window,modal-dialog,Javascript,Extjs,Window,Modal Dialog,我的页面标题上有一个首选项链接,可以打开一个模式窗口(用于修改用户的首选项,如名称或密码) 在“取消”按钮上,我关闭此窗口,但当我尝试重新打开它时,出现以下JS错误: el.addCls.apply(el, arguments); 是我使用了关闭此窗口的好方法,还是问题出在其他地方 这是我的密码: // My window definition Ext.define('jnotes.window.UserPreferences', { extend: 'Ext.window.Windo
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();
};
//我的窗口定义
Ext.define('jnotes.window.UserPreferences'{
扩展:“Ext.window.window”,
布局:“适合”,
莫代尔:是的,
renderTo:Ext.getBody(),
标题:“,
项目:新的Ext.form.Panel({
车身衬垫:5,
waitMsgTarget:是的,
方法:“POST”,
字段默认值:{
labelAlign:'对',
标签宽度:85,
msgTarget:“侧边”
},
defaultType:'textfield',
项目:[{
…//我的田地
}],
按钮:[{
正文:“,
处理程序:函数(){
this.up('form').firevent('validate');
},
}, {
正文:“,
处理程序:函数(){
此.up('form').firevent('cancel');
}
}]
})
});
var preferencesWindow=null;
//打开我的窗户
函数displayPreferences(){
preferencesWindow=Ext.create('jnotes.window.UserPreferences');
var form=首选项向下移动(“形式”);
form.addListener('validate',this.saveUser,this);
form.addListener('cancel',function(){
首选项swindow.close();
preferencesWindow=null;
},这个);
形式负荷({
…//正在加载数据
});
preferencesWindow.show();
};
按照您定义类的方式,表单将在类的所有实例中创建和共享。当你第一次破坏窗口时,窗体也随之被破坏,这就是它的结束
相反,您应该:
a) 指定窗体配置对象:
items: {
xtype: 'form',
// ....
}
b) 在initComponent方法中指定表单,使其绑定到该实例:
Ext.define('MyFoo', {
initComponent: function(){
this.items = new Ext.form.Panel(...);
this.callParent();
}
});
按照您定义类的方式,表单将在类的所有实例中创建和共享。当你第一次破坏窗口时,窗体也随之被破坏,这就是它的结束 相反,您应该: a) 指定窗体配置对象:
items: {
xtype: 'form',
// ....
}
b) 在initComponent方法中指定表单,使其绑定到该实例:
Ext.define('MyFoo', {
initComponent: function(){
this.items = new Ext.form.Panel(...);
this.callParent();
}
});
另一个可能解决问题的解决方案是在窗口配置中指定closeAction:
closeAction: 'hide'
Extjs文档中有关closeAction的更多信息:
单击“关闭页眉”工具时要执行的操作:
可能值:
默认情况下,关闭操作值为destroy。另一个可能解决问题的解决方案是在窗口配置中指定关闭操作:
closeAction: 'hide'
Extjs文档中有关closeAction的更多信息:
单击“关闭页眉”工具时要执行的操作:
可能值:
默认情况下,关闭操作值为destroy。您使用的是哪个版本的ExtJs?错误发生在哪里?错误发生在show调用上。其他信息:我在Firebug中使用断点,它发生在我的表单对象的addCls调用上。您使用的是什么版本的ExtJs?错误发生在哪里?错误发生在show调用上。附加信息:我在Firebug中使用断点,它发生在对我的表单对象的addCls调用上。就是这样!下次我不会忘记的。谢谢!就这样!下次我不会忘记的。谢谢!