Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / data / JsonStore.js
1 /**
2  * @author Ed Spencer
3  * @class Ext.data.JsonStore
4  * @extends Ext.data.Store
5  * @ignore
6  *
7  * <p>Small helper class to make creating {@link Ext.data.Store}s from JSON data easier.
8  * A JsonStore will be automatically configured with a {@link Ext.data.reader.Json}.</p>
9  *
10  * <p>A store configuration would be something like:</p>
11  *
12 <pre><code>
13 var store = new Ext.data.JsonStore({
14     // store configs
15     autoDestroy: true,
16     storeId: 'myStore'
17
18     proxy: {
19         type: 'ajax',
20         url: 'get-images.php',
21         reader: {
22             type: 'json',
23             root: 'images',
24             idProperty: 'name'
25         }
26     },
27
28     //alternatively, a {@link Ext.data.Model} name can be given (see {@link Ext.data.Store} for an example)
29     fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
30 });
31 </code></pre>
32  *
33  * <p>This store is configured to consume a returned object of the form:<pre><code>
34 {
35     images: [
36         {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
37         {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
38     ]
39 }
40 </code></pre>
41  *
42  * <p>An object literal of this form could also be used as the {@link #data} config option.</p>
43  *
44  * @constructor
45  * @param {Object} config
46  * @xtype jsonstore
47  */
48 Ext.define('Ext.data.JsonStore',  {
49     extend: 'Ext.data.Store',
50     alias: 'store.json',
51
52     /**
53      * @cfg {Ext.data.DataReader} reader @hide
54      */
55     constructor: function(config) {
56         config = config || {};
57
58         Ext.applyIf(config, {
59             proxy: {
60                 type  : 'ajax',
61                 reader: 'json',
62                 writer: 'json'
63             }
64         });
65
66         this.callParent([config]);
67     }
68 });