Threaded View

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Location
    Mumbai, INDIA
    Posts
    6
    Vote Rating
    0
    alok0412 is on a distinguished road

      0  

    Default Answered: POSTing deeply nested XML/JSON data

    Answered: POSTing deeply nested XML/JSON data


    Hi all,

    I have a client side data object which looks like this one created after processing a form with some logic:

    Code:
    requestObj =
                    {
                            firstName: "John",
                            lastName : "Doe",
                addresses : [
                                {
                        address: {
                            houseNo : "42", 
                                            street : "abc",
                                            area: "def", 
                                            city: "ghi",
                                            country: "jkl"
                        }
                }    
                ]    
                    };

    I, then, package this object into a model instance created from this model definition:

    Code:
    Ext.define('personalInfo', {
        extend : 'Ext.data.Model',
        config : {
            fields : [
                {name : 'firstName'} ,
                {name : 'lastName'} ,
            ],
            hasMany : [
                {model : 'address', name : 'adresses', associationKey : 'addresses'},
            ]
        }
    });
    
    
    Ext.define('address', {
        extend : 'Ext.data.Model',
        config : {
            fields : [
                    'houseNo', 
                    'street',
                    'area',
                    'city',
                    'country',
            ]
        }
    });
    
    requestModelInstance = new personalInfo(requestObj);
    After this I am binding this with a store which has a proxy and writer configured to make a POST request to my server.



    Code:
    
    var personalInfoUpdateRequest = new Ext.data.Store({
        model : 'personalInfo',
            proxy : {
                    type : 'ajax',
                    url : 'serviceURL',
            headers: { 'Content-Type': 'application/json' },
                    writer : {
                        type : 'json',
                        encode : true,
                        rootProperty : 'personalInfo',
                    }
            }
    });
    
    
    personalInfoUpdateRequest.sync(); // To make the POST

    The POST request is going but the fields I see are only the top level ones, i.e., firstName and lastName. There is no trace of the 'addresses' array. I have tried both XML and JSON infact there seems to be some issue with the requestObj getting packaged into the requestModelInstance.

    There is, practically, no example anywhere in the docs which helps in doing something like this.

    Please help!
    Last edited by alok0412; 11 Apr 2013 at 5:22 AM. Reason: minor typo : requestObject at one place instead of requestObj.

  2. Syncing associated data is not yet supported. You could iterate through the records and associations to build your data structure to send.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar