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
    9,111
    Vote Rating
    470
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      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
    5,560
    Vote Rating
    203
    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


    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]);
        }
    });
    ​

Thread Participants: 2

Tags for this Thread