1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Vote Rating
    1
    Roman_S is on a distinguished road

      0  

    Default Unanswered: Load complex data in form panel

    Unanswered: Load complex data in form panel


    Hi All,

    i have a problem to handle complex json data

    How should I create a form so that I can load and read such json structures?

    Code:
    {
        "order": "order_1",
        "name": "customer_1",
        "address": {
            "city": "city_1",
            "street": "street_1"
        },
        "cargo": {
            "amount": 100
        }
    }
    At the moment a get something like this from my formpanel

    Code:
    xtype: 'form',
    id: 'order_form',
    items: [
        {
            xtype: 'textfield',
            name: 'order'
        },
        {
            xtype: 'textfield',
            name: 'customer'
        },
        {
            xtype: 'fieldset',
            title: 'address',
            items: [
                {
                    xtype: 'textfield',
                    name: 'street',
                    
                },
                {
                    xtype: 'textfield',
                    name: 'city',
                    
                }
            ]
        },
        {
            xtype: 'fieldset',
            title: 'cargo',
            items: [
                {
                    xtype: 'textfield',
                    name: 'amount',
                    
                }
            ]
        }
    ]
    }
    Code:
    {
        "order": "order_1",
        "name": "customer_1",
        "city": "city_1",
        "street": "street_1",
        "amount": 100
    }
    Thanks

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,470
    Answers
    442
    Vote Rating
    202
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    I'm not seeing an out of the box way tot do set nested objects.

    You could use something like:
    Code:
    function setAll (values) {
        form.getForm().setValues(values);
        
        Ext.iterate(values, function (key, val) {
            if (Ext.isObject(val) || Ext.isArray(val)) {
                form.getForm().setValues(val);
                setAll(val);
            } 
        });
    }
    This'll fall apart if you have like-named fields in your nested object, of course, but I'm not seeing a mapping for form fields so anything more complex I'm thinking you'll have to do yourself more manually.

  3. #3
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    64
    Answers
    6
    Vote Rating
    5
    AssetWorks is on a distinguished road

      0  

    Default


    Ext.getCmp('order_form').getForm().loadRecord(values);

Thread Participants: 2

Tags for this Thread