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

一世执手 提交于 2019-12-03 10:16:31

问题


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:


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:

  • Ext.data.DataProxy:
    • Ext.data.DirectProxy
    • Ext.data.HttpProxy
    • Ext.data.MemoryProxy
    • Ext.data.ScriptTagProxy
  • Ext.data.DataWriter
    • Ext.data.JsonWriter
    • Ext.data.XmlWriter
  • Ext.data.DataReader
    • Ext.data.JsonReader
    • Ext.data.XmlReader

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:

  • Ext.data.ArrayStore to make reading from simple Javascript arrays easier
  • Ext.data.DirectStore, just a store preconfigured with an Ext.data.DirectProxy and an Ext.data.JsonReader
  • Ext.data.JsonStore, just a store preconfigured with an Ext.data.JsonReader
  • Ext.data.XmlStore, just a store preconfigured with an Ext.data.XmlReader

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'}]
    });
});



回答2:


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?



来源:https://stackoverflow.com/questions/2130721/whats-basic-difference-between-jsonstore-and-jsonreader-in-context-to-ext-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!