concept store in category ext js

appears as: stores, store, store, The store, stores
Ext JS in Action, Second Edition

This is an excerpt from Manning's book Ext JS in Action, Second Edition.

The data services section takes care of all your data needs, which include fetching, parsing, and loading information into stores. With the Ext JS data services classes you can read Array, XML, and JavaScript Serialized Object Notation (JSON), which is a data format that’s quickly becoming the standard for client-to-server communication. Stores typically feed UI components.

The purpose of Ext.data.Store is to provide a foundation where you can store a local subset of the data available from the server and keep track of changes to this data before sending it back to the server (if your application allows editing of data).

The simplest use of a store is to load inline data in a component. Imagine that you have a typical usage scenario of choosing a title for a person. You can implement this using a ComboBox approach, putting the list of titles in an inline data array like this:

{
    xtype      : 'combo',
    name       : 'title',

    fieldLabel : 'Title',
    queryMode  : 'local',
    valueField : 'title',
    store      : ['Mr.', 'Ms.', 'Dr.']
}

Note that the store declaration takes up only a single line here; the other lines are related to the ComboBox. If this is your first time around Ext JS, this example may seem a bit confusing. Ext JS provides a lot of shortcuts and convenience classes, and this is a prime example.

The ComboBox example doesn’t have a model or fields definition. During the construction phase of the store, Ext JS will create Ext.data.ArrayStore, which uses Ext.data.reader.Array automatically for you and sets it up for use during runtime.

You then add an instance of ArrayReader , which is responsible for sorting out the data retrieved by the proxy and creating new instances of the new user model you just created. When the store loads the data, the array reader reads each record and creates a new instance of User, passing the parsed data to it, which is then loaded into the store.

This completes our end-to-end example of how to create a store that reads array data. With this pattern you can change the type of data the store is able to load. To do this you swap out the ArrayReader with either a JsonReader or an XmlReader. Likewise, if you wanted to change the data source, you could swap out MemoryProxy for another such as Http Proxy, JsonP Proxy, or Direct Proxy.

Listing 8.2. Configuring the model and store