2012-05-17 41 views
0

我開始瘋狂與extjs4和窗體加載。 在我的struts應用程序中,我有一個簡單的表單,我想要加載JSON數據。加載json數據後extjs4表格仍然爲空

問題是數據從服務器正確加載但從未顯示。

下面是代碼:

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數據(intented)響應:

{ 
    "category": 
    { 
     "creationDate": "2012-04-14T22:29:52", 
     "description":"description", 
     "id":1, 
     "label":"Toto" 
    }, 
    "errorMessage":null, 
    "success":true 
} 
+0

並且沒有js錯誤?因爲我認爲「name:'category.id',」會導致js錯誤,因爲json根目錄是category,因此name應該是'id' – nscrob

+0

這是先前嘗試的錯誤。沒有js錯誤。我刪除它,沒有改變,我的表單是空的。 – Patrice

回答

1

最後,我發現在哪裏的問題。

JSON響應必須包含'data'屬性而不是'category'。

替換屬性填寫表單。

相關問題