Ext.onReady(function(){
/****************************************/
/* 主窗体 */
/****************************************/
/****组件****/
/****数据源****/
/****初始化****/
/****事件****/
/*----------------------------------------------------------------------------------------------------------------------*/
var articleClsStore = new Ext.data.Store({
reader:new Ext.data.JsonReader({
totalRecords:'totalCount',//分页时需要的参数
root:'root',//json格式的根节点
fields:[ //在数据库中映射的字段名
{name:'id',type:'int'},
{name:'name',type:'String'}
]
}),
//发送请求得到以上数据
proxy:new Ext.data.HttpProxy({
url:'/RHSite/manager/ArticleClassify)list'
}) }); var articleSpcStore = new Ext.data.Store({
autoLoad:true,
reader:new Ext.data.JsonReader({
totalRecords:'totalCount',
root:'root',
fields:[
{name:'id',type:'int'},
{name:'name',type:'String'}
]
}),
proxy:new Ext.data.HttpProxy({
url:'/RHSite/manager/ArticleSpecail)list'
})
});
Ext.AddArticleWin=Ext.extend(Ext.Window ,{
xtype:"window",
title:"文章管理 - 添加",
width:800,
height:700,
modal:true,
animCollapse:true,
animateTarget:'articleGrid',
bodyStyle:'padding:10px,10px,10px,10px;',
initComponent: function(){
Ext.AddArticleWin.superclass.initComponent.call(this);
}
}) Ext.AddArticleForm=Ext.extend(Ext.form.FormPanel ,{
xtype:"form",
name:'article',
title:'',
labelWidth:100,
labelAlign:"left",
layout:"form",
width:'100%',
bodyStyle:'padding:5px,5px,5px,5px;',
reader: new Ext.data.JsonReader(
{success:'success',root:'data'},
[{name: 'article.id',mapping:'article.id'},
{name: 'article.title',mapping:'article.title'}
]),
initComponent: function(){
this.items=[
{
name:'article.title',
xtype:"textfield",
fieldLabel:"标题",
anchor:"90%"
},
{
name:'article.id',
xtype:"textfield",
fieldLabel:"关键字",
anchor:"70%"
},
{
hiddenName:'article.classify.id',
xtype:"combo",
triggerAction:"all",
fieldLabel:"分类",
loadingText:"正在加载数据...",
anchor:"50%",
store : articleClsStore,
valueField : "id",
displayField : "name",
forceSelection : true
},
{
hiddenName:'article.special.id',
xtype:"combo",
triggerAction:"all",
fieldLabel:"专题",
loadingText:"正在加载数据...",
anchor:"50%",
store : articleSpcStore,
valueField : "id",
displayField : "name",
forceSelection : true
},{
hiddenName:'article.overTime',
xtype:"datefield",
fieldLabel:"有效时间",
anchor:"50%",
format: 'Y-m-d H:i:s'
},{
name:'article.mainContent',
xtype:"textarea",
anchor:"90%",
fieldLabel:"内容",
height:600,
width:450
},{
xtype:"button",
text:"我的按钮",
handler:addArticleEvent
}
],
Ext.AddArticleForm.superclass.initComponent.call(this);
}
})
function addArticleEvent(){
addArticleForm.getForm().submit({
waitMsg: '正在提交数据...',
waitTitle: '提示',
method: 'post',
url:'/RHSite/manager/Article)add',
success: function(form, action) {
var flag=action.result.success;
Ext.Msg.alert('提示',flag);
if(flag == '提交成功'){
Ext.Msg.alert('提示',flag);
}
},
failure: function(form, action) {
Ext.Msg.alert('错误', action.result.error);
}
})
}
var loadFormData = function() {
addArticleForm.getForm().load( {
method:'post',
url : '/RHSite/manager/Article)queryForId?id=186',
waitMsg : '正在载入数据...',
success : function(form,action) {
Ext.Msg.alert("load", action.response.responseText);
},
failure : function(form,action) {
}
});
};
var addArticleWin = new Ext.AddArticleWin({});
var addArticleForm = new Ext.AddArticleForm({});
addArticleWin.add(addArticleForm);
loadFormData();
addArticleWin.show();
// var fckobj = new FCKeditor('article.mainContent', "100%", "500px");
// fckobj.ToolbarSet = 'Default';
// fckobj.ReplaceTextarea();
})
返回的数据为:
{success:true,data:[{'article.id':186,'article.title':'标题4'}]}但表单依然无显示
这样,是一个对象{'article.id':186,'article.title':'标题4'}
{name: 'article.title',mapping:'article.title'}
改成
[{name: 'articleId',mapping:'article.id'},
{name: 'articleTitle',mapping:'article.title'}name:'article.title',
xtype:"textfield",
改成
name:'articleTitle',
xtype:"textfield",name:'article.id',
xtype:"textfield",
改成
name:'articleId',
xtype:"textfield",试试吧。