extjs 怎样从数据库或后台中获取值给form填充默认值
展开全部
form 中的元素用数组,然后用后台传来的 json 给 元素 setValue()
var arr1= new Array();
arr1['id']=new =new Ext.form.TextField ({name:'id', fieldLabel: 'id',value:0});
arr1['name']=new Ext.form.TextField ({name:'name', fieldLabel: '姓名 Name',value:""});
arr1['email']=new Ext.form.TextField ({name:'email', fieldLabel: '电邮地址 Email',value:""});
var formset= new Ext.FormPanel({
frame:true,
trackResetOnLoad : false,
defaults:{labelAlign:'right',labelWidth:60, frame:true,layout:'form'},
fields_arr: arr1 ,
items: [this.fields_arr['id'],
this.fields_arr['name'],
this.fields_arr['email']
],
refrefield:function(config){
for (var key in config){
if (this.fields_arr[key]!==undefined){
this.fields_arr[key].setValue(config[key]);
}
}
},
});
Ext.Ajax.request( {
url : 'user_save.action',
method : 'post',
success : function(response, options) {
var o = Ext.util.JSON.decode(response.responseText);
formset.refrefield(0); //这里给字段赋值
},
failure : function() {
}
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询