Ext4.2MVC controller中使用Ext.getCmp可赋值页面显示但与下面id冲突,使用form.findField()可以赋值不冲突但页面不显示

查威廉姆斯 2013-12-28 03:28:51
MVC中的controller代码
Ext.define('uedit.controller.UeditController', {
extend : 'Ext.app.Controller',
views : [ 'List' ],
models : ['Uedit'],
stores : ['Uedit'],
refs : [ {
ref : 'pageToolBar',
selector : 'list pagingtoolbar'
}, {
ref : 'list',
selector : 'list'
} ],
init : function() {
this.control({
'list button[action=add]':{
click:this.updateUser
}
});
},
onLaunch:function(List){
var me=this;
Ext.Ajax.request({
url : "fetchUserInfo.action",
timeout : 4000,
success : function(response, opts) {
var res = Ext.JSON.decode(response.responseText);
var user = res.userinfo;
var u=user.userName;
var view=Ext.widget('list');
//view.form.findField("userName").setValue(u);
Ext.getCmp("userName").setValue(u);

Ext.getCmp("")
}
});
},
updateUser:function(button){
var record=Ext.create('uedit.model.Uedit');
var view=Ext.widget('list');
view.loadRecord(record);
var form=button.up('form');
var name=form.findField("userName").getValue();
Ext.MessageBox.alert('用户名',name);
if (!form.getForm().isValid()) {
return;
}
var store = this.getUeditStore();
form.getForm().updateRecord(record);
Ext.Ajax.request({
url : 'updateUser.action',
params : {
newUser : Ext.encode(record.data)
},
method : 'POST',
timeout : 2000,
success : function(response, opts) {
Ext.MessageBox.alert('提示','修改成功!');
}
});
}
});
MVC中的VIEW代码
Ext.define('uedit.view.List', {
extend : 'Ext.form.Panel',
title:'信息更改',
alias : "widget.list",
xtype:'form',
layout:'anchor',
bodyPadding:150,
store : 'uedit.sotre.Uedit',
border:false,
frame:true,
url:'',
defaults : {
xtype : 'textfield',
labelWidth : 100,
labelAlign : 'top',
labelStyle:'font-weight:bold'
},
items:[{
id:'userName',
name:'userName',
fieldLabel:'用户名',
allowBlank:false
},{
name:'trueName',
fieldLabel:'真实姓名',
allowBlank:false
},{
name:'mobile',
fieldLabel:'手机',
regex:/^\d{11}$/,
regexText:'手机号码为11位',
allowBlank:false
},{
name:'tel',
fieldLabel:'固话',
regex:/\d{3}-\d{8}|\d{4}-\d{7}/,
allowBlank:false
},{
xtype:'button',
icon:'../image/confirm.ico',
text:'确认更改',
action:'add'
}]
});

使用Ext.getCmp()可以赋值页面上能显示但是下面updateUser运行时报id重复的错误,使用
form.findField().setVlaue()测试是可以赋值与下面updateUser不冲突但是页面上不显示值。。。。。。Ext4MVC刚学不久求助大神
...全文
443 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
是不是重复加载了其他模块了,其他模块也有相同的id配置,改为itemId配置试试。。 itemId:'userName', 然后使用view.form.getComponent("userName").setValue(u);
查威廉姆斯 2013-12-30
  • 打赏
  • 举报
回复

list中已经全部加了id,controller中onLaunch方法中全改为Ext.getCmp方法页面上信息显示但是点击修改时运行updateUser方法是报Ext.Error: Registering duplicate id "userName" with this manager是不是updateUser方法写的有问题。。。
  • 打赏
  • 举报
回复
var name=Ext.getCmp("userName").getValue(); 有id不就统一用getCmp方法就行了

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧