简体   繁体   English

加载json数据后extjs4表单仍然为空

[英]extjs4 form still empty after loading json data

I'm beginning going crazy with extjs4 and form loading. 我开始对extjs4和表单加载感到疯狂。 In my struts application, I have a simple form and i want to load JSON data. 在我的struts应用程序中,我有一个简单的表单,我想加载JSON数据。

The problem is that the data are correctly loaded from the server but never displayed. 问题是数据已从服务器正确加载,但从未显示。

Here is the code : 这是代码:

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"/>
    }
});
});

The JSON data (intented) response : JSON数据(预期)响应:

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

Finally I found where was the problem. 终于我找到了问题所在。

The JSON response must contains the 'data' property instead of 'category'. JSON响应必须包含“数据”属性,而不是“类别”。

Replacing the property fill the form. 替换属性填写表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM