Search code examples
javascriptextjsextjs3

ComboStore is not loading the data


I create a combobox with these are the configuration I given.

displayField: 'TEXT',
valueField: 'ID',

Here is my store

this.store = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({

        url: 'combodata.json',
        actionMethods: {
            read: 'GET'
        },
        reader: new Ext.data.JsonReader({
            rootProperty: 'ROOT.TAG'
        })
    }),
        fields: [
                    {name: 'ID', mapping: 'ID', type: 'string'},
                    {name: 'TEXT', mapping: 'TEXT', type: 'string'}
                ],
        autoLoad: true
    });

And here is my JSON

{
    "ROOT": {
        "TAG": [{
            "ID": 01,
            "TEXT": "ABC"
        },
        {
            "ID": 02,
            "TEXT": "DEF"
        },
        {
            "ID": 03,
            "TEXT": "GHI"
        }]
    }
}

I can see URL is going into response and but data is not loading in combobox. Even data is not going to store itself. Can anyone help me why data is not loading in combo. Update :

this.store = new Ext.data.Store({
            autoLoad: true,
            fields: [
                    {name: 'ID', mapping: 'ID', type: 'string'},
                    {name: 'TEXT', mapping: 'TEXT', type: 'string'}
                ],
            proxy: new Ext.data.HttpProxy({

                url: 'adata.json',//this.url,
                headers: {
                        'Accept': 'application/json; charset=utf-8'
                    },
                actionMethods: {
                    read: 'GET'
                },
                reader: new Ext.data.JsonReader({
                    root: 'ROOT'
                })
            })
        });

Solution

  • I made this fiddle, I'm loading the combo from a JSON file.

    Notice that inside the Assets folder has the JSON file data.json that is loaded by the store.

    As the Lorenz commented, it is necessary to make some changes, take a look, I hope I can help you!