1. #1
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    5
    Vote Rating
    0
    lab-24 is on a distinguished road

      0  

    Default JSON Nested List to Checkbox

    JSON Nested List to Checkbox


    HI,

    Is it possible to bind a nested array (the Roles in the following JSON) to checkboxes in a fieldset?

    [
    {
    "name": "User 1",
    "role": ["admin", "user", "partner"],
    },
    {
    "name": "User 2",
    "role": ["admin"],
    }
    ]

    Roles:
    [ ] superuser
    [x] admin
    [x] user
    [x] partner

    Regards,
    Marcel

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    7,185
    Vote Rating
    194
    scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold

      0  

    Default


    You could create an ArrayStore and then use combo.store.loadData() to load the data.

    Regards,
    Scott.

  3. #3
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    2,216
    Vote Rating
    61
    slemmon is just really nice slemmon is just really nice slemmon is just really nice slemmon is just really nice

      0  

    Default


    Check out setValue for checkboxgroup:
    http://docs.sencha.com/ext-js/4-0/#!...ethod-setValue

    Code:
    var form = ​Ext.widget('form', {
        width: 400
        , renderTo: Ext.getBody()
        , items: [{
            xtype: 'checkboxgroup'
            , defaults: { name: 'role' }
            , items: [{
                boxLabel: 'Superuser'
                , inputValue: 'superuser'
            }, {
                boxLabel: 'Admin'
                , inputValue: 'admin'
            }, {
                boxLabel: 'User'
                , inputValue: 'user'
            }, {
                boxLabel: 'Partner'
                , inputValue: 'partner'
            }]       
        }]
    });
    
    
    Ext.widget('button', {
        text: 'Set Values'
        , renderTo: Ext.getBody()
        , handler: function () {
            var boxes = form.down('checkboxgroup');
            var data = [{"name": "User 1","role": ["admin","user","partner"]},{"name": "User 2","role": ["admin"]}];
            boxes.setValue(data[0]);
        }
    });
    ​

Tags for this Thread