Save nested form data back to server in ExtJS

I have a model that contains an association with another model. I can display nested data in a form using the display attribute on the field. Example:

Ext.define('Example.model.Request', {
    extend: 'Ext.data.Model',

    fields: [
        {
            name: 'id',
            type: Ext.data.Types.NUMBER,
            useNull: false
        }
        {
            name: 'plan_surveyor',
            mapping: 'plan.surveyor',
            type: Ext.data.Types.STRING
        }
    ],

    associations: [
               {type: 'hasOne', associationKey: 'plan', getterName:'getPlan', model: 'Specs.model.Plan'}
              ],

    proxy: {
            type: 'direct',
            api: {
                read: requestController.load,
                 update: requestController.update,
            },
            reader: {
                type: 'json',
                root: 'records'
            },
            writer: {
                type: 'json',
                writeAllFields: true,
                nameProperty: 'mapping'
            }
        }

    });

      

Using this method, I can display the plan.surveyor value in the form under the plan_surveyor link. I am calling Form.loadRecord (model) to pull data from the model into the form.

However, now when I try to send data to the server, I get the error:

Error performing action. Please report the following: "Unrecognized field "plan.surveyor"

I am trying to save to the server by first calling Form.updateRecord (model) then model.save (). Is there a way for Writer to understand that "plan.surveyor" is not a property name and instead handles nesting correctly?

Am I doing this right to get started, or do I just need to handle the form data settings and load back into the model more manually? It looks like nested data isn't all that well supported in general - any recommendation?

+3


source to share


1 answer


    Ext.define('Example.model.Request', {
        extend: 'Ext.data.Model',

        fields: [
            {
                name: 'id',
                type: Ext.data.Types.NUMBER,
                useNull: false
            }
            {
                name: 'plan_surveyor',
                mapping: 'plan.surveyor',//change to 'plan_surveyor'
                type: Ext.data.Types.STRING
            }
        ],

      

the change that shows in the comment because the data index is in the above format, because ur gives ur format which is not dataindex, it is column or extjs, so please change that this might work well



it doesn't work and will send the hole code

0


source







All Articles