ExtJS Window嵌入FormPanel,多次调用报错问题

来源:互联网 发布:nginx 表达式 编辑:程序博客网 时间:2024/05/23 11:34

原始代码:

Ext.define('Gigi.view.user.EditForm', {extend : 'Ext.form.Panel',alias : 'widget.userform',frame : true,bodyPadding : 5,layout: 'anchor',defaults: {labelAlign : 'right',labelWidth : 70,anchor: '100%'},items : [ {xtype : 'textfield',name : 'username',fieldLabel : '用户名',allowBlank: false}, {xtype : 'radiogroup',fieldLabel : '启用',name : 'rgEnabled',items: [{ boxLabel: '是', name: 'enabled', inputValue: 'true', checked : true},{ boxLabel: '否', name: 'enabled', inputValue: 'false'}]}, {xtype : 'radiogroup',fieldLabel : '账号锁定',name : 'rgAccountNonLocked',items: [{ boxLabel: '是', name: 'accountNonLocked', inputValue: 'false' },{ boxLabel: '否', name: 'accountNonLocked', inputValue: 'true', checked : true}]}, {xtype : 'radiogroup',fieldLabel : '账号过期',name : 'rgAccountNonExpired',items: [{ boxLabel: '是', name: 'accountNonExpired', inputValue: 'false' },{ boxLabel: '否', name: 'accountNonExpired', inputValue: 'true', checked : true}]}, {xtype : 'radiogroup',fieldLabel : '密码过期',name : 'rgCredentialsNonExpired',items: [{ boxLabel: '是', name: 'credentialsNonExpired', inputValue: 'false' },{ boxLabel: '否', name: 'credentialsNonExpired', inputValue: 'true', checked : true}]}, {xtype : 'textfield',name : 'email',fieldLabel : 'Email'} ],loadRecord : function(record) {this.callParent(arguments);var rgEnabled = this.down('[name=rgEnabled]');rgEnabled.setValue({enabled : record.get('enabled').toString()});var rgAccountNonLocked = this.down('[name=rgAccountNonLocked]');rgAccountNonLocked.setValue({accountNonLocked : record.get('accountNonLocked').toString()});var rgAccountNonExpired = this.down('[name=rgAccountNonExpired]');rgAccountNonExpired.setValue({accountNonExpired : record.get('accountNonExpired').toString()});var rgCredentialsNonExpired = this.down('[name=rgCredentialsNonExpired]');rgCredentialsNonExpired.setValue({credentialsNonExpired : record.get('credentialsNonExpired').toString()});},initComponent : function() {if (this.initialConfig  && ('update' == this.initialConfig.actionType)) {this.items[0].readOnly = true;} else {this.items[0].readOnly = false;}this.callParent(arguments);}});Ext.define('Gigi.view.user.Edit', {extend : 'Ext.window.Window',alias : 'widget.useredit',layout : 'fit',autoShow : true,actionType : 'create',items : [Ext.widget('userform', {actionType : this.actionType})],initComponent : function() {this.buttons = [ {text : '保存',action : 'save'}, {text : '取消',scope : this,handler : this.close} ];this.callParent(arguments);}});


以上代码,第一调用Ext.widget('useredit')时正常显示弹出窗,第二次调用无法正常显示,报如下错误:

Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLDivElement.insertBefore]

解决方法,修改Gigi.view.user.Edit,将form的构建放入initComponent方法中,而不是通过config方式声明,代码如下:

Ext.define('Gigi.view.user.Edit', {extend : 'Ext.window.Window',alias : 'widget.useredit',layout : 'fit',autoShow : true,actionType : 'create',initComponent : function() {var form = Ext.widget('userform', {actionType : this.actionType});this.items = [form];this.buttons = [ {text : '保存',action : 'save'}, {text : '取消',scope : this,handler : this.close} ];this.callParent(arguments);}});


原创粉丝点击