views:

2927

answers:

2

what's basic difference between JsonStore and JsonReader in context to Ext.data ?

I mean when I should go for JsonStore and when I should use JsonReader as for me both are providing same solution.

+1  A: 

A JsonReader reads JSON from a data source into an Ext Store. JsonData is not a specifically-defined Ext object, although maybe you've seen it as a variable name? In what context are you using it?

bmoeskau
Here is an Example,Example using Reader var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/db?cmd=list' }), reader: new Ext.data.JsonReader( {root: 'row', fields:['name']} ) });store.load();Example two with JsonStorevar store = new Ext.data.JsonStore({ url: '/db?cmd=list', root: 'row', fields: ['name'] }); store.load();
Tumbleweed
Just as a note, you originally asked the difference between JsonReader and *JsonData*, which obviously was a typo since you've edited your question to change that (without noting it). Just wanted to clarify so that my answer does not look so random. As Stefan explains below, JsonStore is a convenience class. If you are loading JSON via HTTP, it simply saves you some configuration effort, but it is equivalent to using a JsonReader plus an HttpProxy.
bmoeskau
+5  A: 

Actually they are two separate things. A Ext.data.JsonReader reads a given JSON object and returns data records (Ext.data.Record objects) that are later stored by the respective data store.

The Ext.data.Store is the base class for all Ext storages and uses helper objects for retrieving data (Ext.data.DataProxy), for writing data (Ext.data.DataWriter) and for reading data (Ext.data.DataReader). These base classes come in different flavors such as:

This all builds up to a very extendable component that allows the developer to configure exactly what he needs to tweak. To make it easier for developers (especially new ones) Ext comes with some pre-configured data stores:

So actually a Ext.data.JsonStore is just a convenience class to make it easier for the developer.

The following two snippets will create the same (or comparable) stores:

var store = new Ext.data.JsonStore({
    url: 'get-images.php',
    root: 'images',
    idProperty: 'name',
    fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});

// or 

var store = new Ext.data.Store({
    url: 'get-images.php',
    reader: new Ext.data.JsonReader({
        root: 'images',
        idProperty: 'name',
        fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
    });
});
Stefan Gehrig