日期:2014-05-16  浏览次数:20388 次

以JSON的值初始化Ext.Form`

在Form的定义部分添加一个Reader

程序代码
var fs = new Ext.FormPanel({
frame: true,
title:'XML Form',
labelAlign: 'right',
labelWidth: 85,
width:340,
waitMsgTarget: true,
reader : new Ext.data.JsonReader({
root : 'article',
success : '@success'
}, [
{
name : 'title',
mapping : 'title'
}]),
items: [
new Ext.form.FieldSet({
title: 'Contact Information',
autoHeight: true,
defaultType: 'textfield',
items: [{
fieldLabel: ''title'',
name: 'first',
width:190
})
]
})
]
});
?

通过调用

程序代码
fs.getForm().load({url:'loadArticle.action?articleId=6', waitMsg:'Loading'});
?

就可以取到返回的JSON值并设置给Form``

不过这里要注意一点的就是``JSONREADER中的root项要对应一个数组`也就是说JSON的返回格式``要以`

程序代码
{"article":[
{"title":"title111"}
]}
?

不能是`

程序代码
{"article":
{"title":"title111"}
}
?