Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: How do I get raw JSON data from Ext.data.Store?

Tags:

extjs4

From a typical store like this

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'firstName', type: 'string'},
        {name: 'lastName',  type: 'string'},
        {name: 'age',       type: 'int'},
        {name: 'eyeColor',  type: 'string'}
    ]
});

var myStore = Ext.create('Ext.data.Store', {
    model: 'User',
    proxy: {
        type: 'ajax',
        url : '/users.json',
        reader: {
            type: 'json',
            root: 'users'
        }
    },
    autoLoad: true
});

Is it possible to get raw Json from myStore?

like image 594
c.sokun Avatar asked Feb 05 '12 17:02

c.sokun


People also ask

What is rootProperty in ExtJs?

rootProperty: the property name of the root response node containing the record data. totalProperty: property name for the total number of records in the data. successProperty: property name for the success status of the response. messageProperty: property name for an optional response message.

What is data package used for in ExtJs?

The data package is what loads and saves all of the data in your application. It consists of a multitude of classes, but there are three that are more important than all the others.

What is proxy in ExtJs?

In ExtJs have store proxy and also Ajax request you can use both. Proxies are used by Ext. data. Store to handle the loading and saving of Ext. data.


3 Answers

The accepted solution did not work in my configuration: ExtJs 4.1 and a grid with a memory proxy - it returned empty after I added items to the gird (and the store object reflected that). The following code worked for encoding store contents into a JSON string:

var json = Ext.encode(Ext.pluck(store.data.items, 'data'));

Cheers!

like image 132
Timur K Avatar answered Sep 30 '22 13:09

Timur K


What about:

myStore.proxy.reader.rawData
like image 29
Grant Zhu Avatar answered Sep 30 '22 14:09

Grant Zhu


Took me ages to find a solution to this but here is one solution that will work.

    myStore .on({ 'load': function (store, records, successful)
    {
        console.log(store.getProxy().getReader().rawData);
    } 
    });
like image 25
Tenerezza Avatar answered Sep 30 '22 14:09

Tenerezza