Reader root in ExtJS with nested JSON array

后端 未结 1 1046

I\'m trying to fill the grid with part of data i\'m taking from JSON. For example (shortnen version), JSON looks like this:

 {
  \"data\": [
    {
      \"name\"         


        
相关标签:
1条回答
  • 2021-01-25 09:09

    Using 'data[0].devices.disk' worked for me. Your example JSON was a little messed up though with some trailing commas.

    jsFiddle

    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: ['type', 'device']
    });
    
    Ext.onReady(function() {
        var myData = '{"data":[{"name":"machine1","devices":{"disk":[{"type":"file","device":"disk"},{"type":"block","device":"cdrom"}]}},{"name":"machine2","devices":{"disk":[{"type":"file","device":"disk"},{"type":"block","device":"cdrom"}]}}]}';
    
        var store = Ext.create('Ext.data.Store', {
            model: 'User',
            data: Ext.decode(myData),
            proxy: {
                type:'memory',
                reader: {
                    type:'json',
                    root: 'data[0].devices.disk'
                }
            }
        });
    
        Ext.create('Ext.grid.Panel', {
            store: store,
            stateful: true,
            collapsible: true,
            multiSelect: true,
            stateId: 'stateGrid',
            columns: [
                {
                    text     : 'type',
                    dataIndex: 'type'
                },
                {
                    text     : 'device',
                    dataIndex: 'device'
                }
            ],
            height: 350,
            width: 600,
            title: 'Array Grid',
            renderTo: 'grid',
            viewConfig: {
                stripeRows: true,
                enableTextSelection: true
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题