论坛首页 AJAX版 EXT

请教ExtJs的表单动态填充的问题

浏览 1066 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-07-16
需求:是在grid中选择一项,然后点击"修改",会弹出表单窗体,并且该表单窗体的项会被已有的数据填充
问题:第一次选择一项后,能正常的向url地址发送请求,并且得到正确的JSON,表单能被正确填充.关闭窗体后,再另外选择一项,则IE浏览器会报:this.form.el.dom不是对象或为空对象,窗体能够弹出,但是显示的是第一项的内容.查看后台日志,发现并没有向url地址发送请求.
我的解决经历(未成功):1.将ID都取消,无效
2,将new Ext.data.JsonReader这个放在new Ext.form.FormPanel的 reader属性中也无效.
3,搜索了一些例子,也不管用

痛苦的挣扎了很久,还是搞不定,特来请教

出问题的代码:

function updateGameWin(grid) {
				var record = grid.getSelectionModel().getSelected();
				if (!record) {
					Ext.Msg.alert("修改操作", "请选择要修改的一项");
				} else {
					// Ext.Msg.alert("已经选择");
					// 表单对象
					var javagameReader = new Ext.data.JsonReader({
						// id:'gameid',
						root : 'data',
						successProperty: 'success'
					}, [{
						name : 'gameid',
						mapping : 'gameid'
					}, {
						name : 'gamename',
						mapping : 'gamename'
					}, {
						name : 'serial',
						mapping : 'serial'
					}, {
						name : 'developer',
						mapping : 'developer'
					}, {
						name : 'price',
						mapping : 'price'
					}, {
						name : 'typeId',
						mapping : 'typeId'
					}, {
						name : 'playtype',
						mapping : 'playtype'
					}, {
						name : 'introduction',
						mapping : 'introduction'
					}, {
						name : 'mboxurl',
						mapping : 'mboxurl'
					},]

					);

					gameTypeStore.load();
					// 图片上传
					var logoUploadField = new Ext.form.TextField({
						//id : 'logoUploadField',
						fieldLabel : '游戏LOGO图片',
						name : 'picture',
						// allowBlank : false,
						anchor : '90%',
						height : 20,
						inputType : 'file',
						length:100
					});

					// // 游戏简介字段
					var introductionField = new Ext.form.TextArea({
						//id : 'introductionField',
						fieldLabel : '游戏简介',
						// width : 100,
						height : 140,
						name : 'introduction',
						allowBlank : false,
						anchor : '90%'
							// growMin : 234
					});
					// 图片上传
					var logoUploadField = new Ext.form.TextField({
						//id : 'logoUploadField',
						fieldLabel : '游戏LOGO图片',
						name : 'picture',
						// allowBlank : false,
						anchor : '90%',
						height : 20,
						inputType : 'file'
					});


					var updateForm = new Ext.form.FormPanel({
						//id : 'updateForm',
						labelAlign : 'top',
						frame : true,
						width : 500,
						url : 'updategame.action',
						fileUpload : true,
						reader : javagameReader,

						items : [{
							layout : 'column',// 该FormPanel的layout布局模式为列模式(column),包含2列
							items : [{// 第一列
								columnWidth : 0.5,
								layout : 'form',
								items : [gamenameField, developerField,
										playtypeField]

							}, {	// 第二列
								columnWidth : 0.5,
								layout : 'form',
								items : [serialField, priceField, typeIdField

								]
							}]
						}, logoUploadField, introductionField],

						buttons : [{
							text : '保存',
							disabled : false,
							handler : function() {
								if (updateForm.form.isValid()) {
									updateForm.form.submit({
										// url : 'AddLevel.action',
										success : function(form, action) {
											form.reset();
											Ext.MessageBox.alert('成功',
													'修改游戏成功!');

											store.load({
												params : {
													start : 0,
													limit : 10
												}
											});

										},
										failure : function(form, action) {
										
											Ext.MessageBox.alert('失败',
													'修改游戏失败!');
										},
										waitMsg : '正在保存数据,稍后...'
									});

									updateGameFormWin.hide();
								} else {
									Ext.Msg.alert('信息', '请填写完成再提交!');
								}
							}
						}, {
							text : '取消',
							handler : function() {
								// addForm.getForm().reset();
								updateGameFormWin.hide();
								// updateGameFormWin.close();无效

							}
						}]
					});
					//alert(updateForm.form),此处可以获得object Object;
                                             //alert(record.get('gameid'),能得到不同的值
					updateForm.form.load({
						url : 'testById.action?gameid='+ record.get('gameid'),
						waitMsg : '正在载入数据...',
						success : function(form,action) {
                    		//Ext.example.msg'编辑', '载入成功!');
                		},
                		failure : function(form,action) {
                    		Ext.MessageBox.alert('编辑', '载入失败');
                		}

					});

					if (!updateGameFormWin) {
						updateGameFormWin = new Ext.Window({
							layout : 'fit',
							width : 500,
							height : 500,
							closable : true,
							closeAction : 'hide',
							plain : true,
							title : '修改游戏',
							items : updateForm
						});
					}

					updateGameFormWin.show(Ext.get('updateGameButton'));

				}
			}

   
最后更新时间:2008-07-16
closeAction : 'hide',  
去掉这行应该可以吧,
出现在第一行的数据的问题就是在于这里。

this.form.el.dom
那是因为你新添一个form,但是没有layout,layout依然是第一个from.所以this找不到就很正常了

不知道上面说的对不对
   
0 请登录后投票
最后更新时间:2008-07-16
如果不想每次都生成win
可以把
items : updateForm  
这个改成动态的
比如在前面加t=this;
之后
把 items : updateForm 改成items : t.updateForm
要看你的调用方式。有可能this指的不是updateGameWin这个对象。这样的话,可以把var updateForm = new Ext.form.FormPanel({  
改成var updateForm =this.updateForm = new Ext.form.FormPanel({

碰到类似的问题,我是这样的解决的。不知道有效没有
   
0 请登录后投票
最后更新时间:2008-07-16
jljlpch 写道
如果不想每次都生成win
可以把
items : updateForm  
这个改成动态的
比如在前面加t=this;
之后
把 items : updateForm 改成items : t.updateForm
要看你的调用方式。有可能this指的不是updateGameWin这个对象。这样的话,可以把var updateForm = new Ext.form.FormPanel({  
改成var updateForm =this.updateForm = new Ext.form.FormPanel({

碰到类似的问题,我是这样的解决的。不知道有效没有


请问下t=this是加在哪?
加在function updateGameWin(grid) 之前吗?

=============================================
还有个问题:看到某位大老说的,直接读取开始读到的grid 的数据,然后再填充到表单中

他举的方法:
"利用
grid.getSelectionModel().getSelected()
取得选中的行对应的record
然后调用 form的 loadRecord 方法 就可以了
很简单的."

"grid.getSelectionModel().getSelected()
取得选中的行对应的record "
这里我是可以做到的

单个的属性也是能够利用setValue()设置进 form里,后面的   "调用 form的 loadRecord 方法",
我硬套了一下,没什么用,不知道具体该怎么用,formPanel里面还需要设reader吗??

小子刚学EXTJS,很多初级问题不懂,忘各位不要见怪
   
0 请登录后投票
最后更新时间:2008-07-16
写在该函数第一行就可以了。

对于直接从grid取数的问题?
你说的是从grid中的data store中取值吧。是不要用后台取得数据。
之后利用form 's load初始化就可以了
   
0 请登录后投票
最后更新时间:2008-07-16
form 有两种,一种是submit,一种是load.用load能直接填充的。
   
0 请登录后投票
最后更新时间:2008-07-16
formpanel.form.loadRecord(Record)
   
0 请登录后投票
最后更新时间:2008-07-16
jljlpch 写道
formpanel.form.loadRecord(Record)

我用此方法今天下午没弄进去
明天上班再试试
   
0 请登录后投票
最后更新时间:2008-07-18
不行哦,我也碰到了这个问题。
   
0 请登录后投票
最后更新时间:2008-07-18
搞定,formpanel.getForm().loadRecord(record);
这样就没问题了。
   
0 请登录后投票
论坛首页 AJAX版 EXT

跳转论坛:
JavaEye推荐