[英]extjs4 form still empty after loading json data
我開始對extjs4和表單加載感到瘋狂。 在我的struts應用程序中,我有一個簡單的表單,我想加載JSON數據。
問題是數據已從服務器正確加載,但從未顯示。
這是代碼:
Ext.onReady(function(){
var formPanel = Ext.create('Ext.form.Panel', {
renderTo: Ext.get('categoryForm'),
width: 340,
bodyPadding: 5,
waitMsgTarget: true,
url: '<s:url value="json/save" />',
method: 'POST',
loader: {
type: 'json',
root: 'category',
successProperty: 'success'
},
fieldDefaults: {
labelAlign: 'right',
labelWidth: 85,
msgTarget: 'side'
},
defaultType: 'textfield',
items: [{
name: 'category.id',
hidden: true
}, {
fieldLabel: "<s:text name="category.label"/>",
name: 'label',
allowBlank: false,
maxLength: 35
}, {
fieldLabel: "<s:text name="category.description"/>",
name: 'description',
xtype: 'textarea',
maxLength: 250
}, {
fieldLabel: '<s:text name="category.creationDate"/>',
name: 'creationDate',
xtype: 'datefield',
readOnly: true
}],
buttons: [{
text: "<s:text name="action.modify"/>",
handler: function() {
formPanel.getForm().submit();
}
}, {
text: "<s:text name="action.cancel"/>",
handler: function() {
formPanel.getForm().reset();
}
}]
});
formPanel.show();
formPanel.load({
url: '<s:url action="json/load"/>',
params: {
categoryId: <s:property value="categoryId"/>
}
});
});
JSON數據(預期)響應:
{
"category":
{
"creationDate": "2012-04-14T22:29:52",
"description":"description",
"id":1,
"label":"Toto"
},
"errorMessage":null,
"success":true
}
終於我找到了問題所在。
JSON響應必須包含“數據”屬性,而不是“類別”。
替換屬性填寫表格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.