Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / JsonStore.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-data-JsonStore'>/**
19 </span> * @author Ed Spencer
20  * @class Ext.data.JsonStore
21  * @extends Ext.data.Store
22  * @ignore
23  *
24  * &lt;p&gt;Small helper class to make creating {@link Ext.data.Store}s from JSON data easier.
25  * A JsonStore will be automatically configured with a {@link Ext.data.reader.Json}.&lt;/p&gt;
26  *
27  * &lt;p&gt;A store configuration would be something like:&lt;/p&gt;
28  *
29 &lt;pre&gt;&lt;code&gt;
30 var store = new Ext.data.JsonStore({
31     // store configs
32     autoDestroy: true,
33     storeId: 'myStore',
34
35     proxy: {
36         type: 'ajax',
37         url: 'get-images.php',
38         reader: {
39             type: 'json',
40             root: 'images',
41             idProperty: 'name'
42         }
43     },
44
45     //alternatively, a {@link Ext.data.Model} name can be given (see {@link Ext.data.Store} for an example)
46     fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
47 });
48 &lt;/code&gt;&lt;/pre&gt;
49  *
50  * &lt;p&gt;This store is configured to consume a returned object of the form:&lt;pre&gt;&lt;code&gt;
51 {
52     images: [
53         {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
54         {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
55     ]
56 }
57 &lt;/code&gt;&lt;/pre&gt;
58  *
59  * &lt;p&gt;An object literal of this form could also be used as the {@link #data} config option.&lt;/p&gt;
60  *
61  * @xtype jsonstore
62  */
63 Ext.define('Ext.data.JsonStore',  {
64     extend: 'Ext.data.Store',
65     alias: 'store.json',
66
67 <span id='Ext-data-JsonStore-cfg-reader'>    /**
68 </span>     * @cfg {Ext.data.DataReader} reader @hide
69      */
70     constructor: function(config) {
71         config = config || {};
72
73         Ext.applyIf(config, {
74             proxy: {
75                 type  : 'ajax',
76                 reader: 'json',
77                 writer: 'json'
78             }
79         });
80
81         this.callParent([config]);
82     }
83 });
84 </pre>
85 </body>
86 </html>