Download Extjs Json without Root

My problem is that the json I get does not have a root. I can get the repository to load the URL and I return JSON, but the repository data is empty and nothing is displayed 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 also tried removing the root, but nothing returned in the repository or callback. My googlefu does nothing good on json without root.

+4
source share
2 answers

the root must be defined as empty root:''

Here is the code showing the correct 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.

+2
source

expandable Ext.data.reader.Jsonto customize your answer. Use it inside a proxy reader.

+1

Source: https://habr.com/ru/post/1544390/


All Articles