Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / data / JsonStore.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @author Ed Spencer
17  * @class Ext.data.JsonStore
18  * @extends Ext.data.Store
19  * @ignore
20  *
21  * <p>Small helper class to make creating {@link Ext.data.Store}s from JSON data easier.
22  * A JsonStore will be automatically configured with a {@link Ext.data.reader.Json}.</p>
23  *
24  * <p>A store configuration would be something like:</p>
25  *
26 <pre><code>
27 var store = new Ext.data.JsonStore({
28     // store configs
29     autoDestroy: true,
30     storeId: 'myStore',
31
32     proxy: {
33         type: 'ajax',
34         url: 'get-images.php',
35         reader: {
36             type: 'json',
37             root: 'images',
38             idProperty: 'name'
39         }
40     },
41
42     //alternatively, a {@link Ext.data.Model} name can be given (see {@link Ext.data.Store} for an example)
43     fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
44 });
45 </code></pre>
46  *
47  * <p>This store is configured to consume a returned object of the form:<pre><code>
48 {
49     images: [
50         {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
51         {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
52     ]
53 }
54 </code></pre>
55  *
56  * <p>An object literal of this form could also be used as the {@link #data} config option.</p>
57  *
58  * @xtype jsonstore
59  */
60 Ext.define('Ext.data.JsonStore',  {
61     extend: 'Ext.data.Store',
62     alias: 'store.json',
63
64     /**
65      * @cfg {Ext.data.DataReader} reader @hide
66      */
67     constructor: function(config) {
68         config = config || {};
69
70         Ext.applyIf(config, {
71             proxy: {
72                 type  : 'ajax',
73                 reader: 'json',
74                 writer: 'json'
75             }
76         });
77
78         this.callParent([config]);
79     }
80 });
81