//formPanel的items如下所示:
{
fieldLabel : '新闻标题',
name : 'news.subject',
width :400,
id : 'subject'
},{
fieldLabel:'桌面新闻',
name:'isDeskImage',
id:'isDeskImage',
xtype:'checkbox',
handler:function(obj){
if(obj.getValue()){
Ext.getCmp('CheckOutImageButton').show();
}else{
Ext.getCmp('CheckOutImageButton').hide();
}
}
//.................
//加载数据
this.formPanel.getForm().load({
deferredRender : false,
url : __ctxPath + '/info/getNews.do?newsId=' + this.newsId,
waitMsg : '正在载入数据...',
success : function(form, action) {
},
failure : function(form, action) {
Ext.ux.Toast.msg('编辑', '载入失败');
}
});
{success:true,data:{"author":"csx","content":"宏天jofficeOA
","createtime":1284706528000,"firstKeyColumnName":"newsId","id":5,"isDeskImage":1,"issuer":"csx","newsId":5,"newsType":{"class":"com.htsoft.oa.model.info.NewsType_$$_javassist_118","sn":3,"typeId":4,"typeName":"宏天jofficeOA"},"replyCounts":3,"status":1,"subject":"宏天jofficeOA","subjectIcon":"info/news/201009/7de72a2ab73e4ced9779a87606d96b1f.jpg","typeId":4,"updateTime":1285482215000,"viewCounts":51}}
Ext.override(Ext.Panel, {
loadData:function(conf){
var ct=this;
//遍历该表单下所有的子项控件,并且为它赋值
var setByName=function(container,data){
var items=container.items;
if(items!=null){
for(var i=0;i var comp=items.get(i);
if(comp.items){
setByName(comp,data);
continue;
}
//判断组件的类型,并且根据组件的名称进行json数据的自动匹配
var xtype=comp.getXType();
try{
if(xtype=='textfield' || xtype=='textarea' || xtype=='radio' || xtype=='checkbox'
|| xtype=='datefield' || xtype=='combo' || xtype=='hidden' || xtype=='datetimefield'
||xtype=='htmleditor'
|| xtype=='label' || xtype=='fckeditor'
){
var name=comp.getName();
if(name){
if(conf.preName){
name=name.substring(conf.preName.length+1);
}
var val=eval('data.'+name);
if(val){
comp.setValue(val);
}
}
}
}catch(e){
//alert(e);
}
}
}
};
if (!ct.loadMask) {
ct.loadMask = new Ext.LoadMask(Ext.getBody());
ct.loadMask.show();
}
Ext.Ajax.request({
method:'POST',
url:conf.url,
scope:this,
success:function(response,options){
var json=Ext.util.JSON.decode(response.responseText);
var data=null;
if(conf.root){
data=eval('json.'+conf.root);
}else{
data=json;
}
setByName(ct,data);
if(ct.loadMask){
ct.loadMask.hide();
ct.loadMask = null;
}
if(conf.success){
conf.success.call(ct,response,options);
}
},//end of success
failure:function(response,options){
if(ct.loadMask){
ct.loadMask.hide();
ct.loadMask = null;
}
if(conf.failure){
conf.failure.call(ct,response,options);
}
}
});
}
});
this.formPanel.loadData({
root : 'data',
preName:'news',
url : __ctxPath + '/info/getNews.do?newsId=' + this.newsId,
success : function(form, action) {
},
failure : function(form, action) {
Ext.ux.Toast.msg('编辑', '载入失败');
}
});
Ext.override(Ext.Container, {
getCmpByName : function(name) {
var getByName = function(container, name) {
var items = container.items;
if (items != null) {
for (var i = 0; i < items.getCount(); i++) {
var comp = items.get(i);
var cp = getByName(comp, name);
if (cp != null)
return cp;
if (comp.getName && name == comp.getName()) {
return comp;
break;
}
}
}
return null;
};
return getByName(this, name);
}
});