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刚学不久求助大神