JesseRules
JesseRules

Reputation: 723

Extjs Json load without Root

My problem is the json I am getting doesn't have a root. I can get the store to load the URL and I get the JSON back but the store data is empty and nothing shows in the callback.

Json:
[
{
    "symbol": "GM"
},
{
    "symbol": "GA"
}
]

Model and Store:

Ext.define('Symbol', {
extend: 'Ext.data.Model',
fields: ['symbol']
});


Ext.define('Doc.store.symbol', {
extend: 'Ext.data.Store',
model: 'Symbol',
proxy: {
    type: 'jsonp',
    url: 'datasource/symbol',
    reader: {
        type: 'json',
        model: 'symbol'
    },
}
});

I tried removing the root as well but nothing came back in the store or the callback. My googlefu is turning up nothing good on json without root.

Upvotes: 4

Views: 1864

Answers (2)

weeksdev
weeksdev

Reputation: 4355

the root should be defined as blank root:''

Here is a code demonstrating the proper setup:

       Ext.define('boomer', {
            extend:'Ext.data.Model',
            fields: ['symbol'],
            proxy: {
                type: "ajax",
                url: "data.json",
                extraParams: {
                },
                reader: {
                    type: "json",
                    root: "",
                    successProperty: "success"
                }
            }
        });
        var store = Ext.create('Ext.data.Store',{
            model: 'boomer',
        });
        store.load({
            callback:function(){
                Ext.Msg.alert('Store Items', store.data.items.length);
                console.log(store.data.items);
            }
        });

Here is a fiddle demonstrating working code.

Upvotes: 2

sakir
sakir

Reputation: 3502

extend Ext.data.reader.Json to adjust your response.Later use it inside proxy reader.

there is a answer here

Upvotes: 1

Related Questions