commit extjs-2.2.1
[extjs.git] / docs / output / Ext.data.JsonReader.html
1         <div class="body-wrap">
2         <div class="top-tools">
3             <a class="inner-link" href="#Ext.data.JsonReader-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a>
4             <a class="inner-link" href="#Ext.data.JsonReader-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a>
5             <a class="inner-link" href="#Ext.data.JsonReader-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a>
6                             <a class="inner-link" href="#Ext.data.JsonReader-configs"><img src="../resources/images/default/s.gif" class="item-icon icon-config">Config Options</a>
7                         <a class="bookmark" href="../docs/?class=Ext.data.JsonReader"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a>
8         </div>
9                 <div class="inheritance res-block">
10 <pre class="res-block-inner"><a ext:cls="Ext.data.DataReader" ext:member="" href="output/Ext.data.DataReader.html">DataReader</a>
11   <img src="resources/elbow-end.gif"/>JsonReader</pre></div>
12                 <h1>Class Ext.data.JsonReader</h1>
13         <table cellspacing="0">
14             <tr><td class="label">Package:</td><td class="hd-info">Ext.data</td></tr>
15             <tr><td class="label">Defined In:</td><td class="hd-info"><a href="../src/JsonReader.js" target="_blank">JsonReader.js</a></td></tr>
16             <tr><td class="label">Class:</td><td class="hd-info">JsonReader</td></tr>
17                         <tr><td class="label">Subclasses:</td><td class="hd-info"><a ext:cls="Ext.data.ArrayReader" href="output/Ext.data.ArrayReader.html">ArrayReader</a></td></tr>
18                                     <tr><td class="label">Extends:</td><td class="hd-info"><a ext:cls="Ext.data.DataReader" ext:member="" href="output/Ext.data.DataReader.html">DataReader</a></td></tr>
19                     </table>
20         <div class="description">
21             *
22 Data reader class to create an Array of <a ext:cls="Ext.data.Record" href="output/Ext.data.Record.html">Ext.data.Record</a> objects from a JSON response
23 based on mappings in a provided <a ext:cls="Ext.data.Record" href="output/Ext.data.Record.html">Ext.data.Record</a> constructor.<br>
24 <p>
25 Example code:
26 <pre><code>var Employee = Ext.data.Record.create([
27     {name: <em>'firstname'</em>},                  <i>// Map the Record<em>'s "firstname" field to the row object'</em>s key of the same name</i>
28     {name: <em>'job'</em>, mapping: <em>'occupation'</em>}  <i>// Map the <em>"job"</em> field to the row object's <em>"occupation"</em> key</i>
29 ]);
30 <b>var</b> myReader = <b>new</b> Ext.data.JsonReader({
31     totalProperty: <em>"results"</em>,             <i>// The property which contains the total dataset size (optional)</i>
32     root: <em>"rows"</em>,                         <i>// The property which contains an Array of row objects</i>
33     id: <em>"id"</em>                              <i>// The property within each row object that provides an ID <b>for</b> the record (optional)</i>
34 }, Employee);</code></pre>
35 <p>
36 This would consume a JSON object of the form:
37 <pre><code>{
38     results: 2,
39     rows: [
40         { id: 1, firstname: <em>'Bill'</em>, occupation: <em>'Gardener'</em> },         <i>// a row object</i>
41         { id: 2, firstname: <em>'Ben'</em> , occupation: <em>'Horticulturalist'</em> }  <i>// another row object</i>
42     ]
43 }</code></pre>
44 <p>It is possible to change a JsonReader's metadata at any time by including a
45 <b><tt>metaData</tt></b> property in the data object. If this is detected in the
46 object, a <a ext:cls="Ext.data.Store" href="output/Ext.data.Store.html">Store</a> object using this Reader will reconfigure
47 itself to use the newly provided field definition and fire its
48 <a ext:cls="Ext.data.Store" ext:member="metachange" href="output/Ext.data.Store.html#metachange">metachange</a> event. In
49 undergoing this change, the Store sets its <a ext:cls="Ext.data.Store" ext:member="sortInfo" href="output/Ext.data.Store.html#sortInfo">sortInfo</a> property
50 from the <tt>sortInfo</tt> property in the new metadata. Note that reconfiguring a Store
51 potentially invalidates objects which may refer to Fields or Records which no longer exist.</p>
52 <p>The <b><tt>metaData</tt></b> property may contain any of the configuration
53 options for this class. Additionally, it may contain a <b><tt>fields</tt></b>
54 property which the JsonReader will use as an argument to <a ext:cls="Ext.data.Record" ext:member="create" href="output/Ext.data.Record.html#create">Ext.data.Record.create</a>
55 to configure the layout of the Records which it will produce.<p>
56 Using the <b><tt>metaData</tt></b> property, and the Store's <a ext:cls="Ext.data.Store" ext:member="metachange" href="output/Ext.data.Store.html#metachange">metachange</a> event,
57 it is possible to have a Store-driven control initialize itself. The metachange
58 event handler may interrogate the <b><tt>metaData</tt></b> property (which
59 may contain any user-defined properties needed) and the <b><tt>metaData.fields</tt></b>
60 property to perform any configuration required.</p>
61 <p>To use this facility to send the same data as the above example without
62 having to code the creation of the Record constructor, you would create the
63 JsonReader like this:</p><pre><code>var myReader = <b>new</b> Ext.data.JsonReader();</code></pre>
64 <p>The first data packet from the server would configure the reader by
65 containing a metaData property as well as the data:</p><pre><code>{
66     metaData: {
67         totalProperty: <em>'results'</em>,
68         root: <em>'rows'</em>,
69         id: <em>'id'</em>,
70         fields: [
71             {name: <em>'name'</em>},
72             {name: <em>'occupation'</em>}
73         ]
74     },
75     results: 2,
76     rows: [
77         { <em>'id'</em>: 1, <em>'name'</em>: <em>'Bill'</em>, occupation: <em>'Gardener'</em> },
78         { <em>'id'</em>: 2, <em>'name'</em>: <em>'Ben'</em>, occupation: <em>'Horticulturalist'</em> }
79     ]
80 }</code></pre>        </div>
81         
82         <div class="hr"></div>
83                 <a id="Ext.data.JsonReader-configs"></a>
84         <h2>Config Options</h2>
85         <table cellspacing="0" class="member-table">
86             <tr>
87                 <th class="sig-header" colspan="2">Config Options</th>
88                 <th class="msource-header">Defined By</th>
89             </tr>
90                 <tr class="config-row">\r
91         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
92         <td class="sig">\r
93         <a id="Ext.data.JsonReader-id"></a>\r
94             <b>id</b> : String            <div class="mdesc">\r
95                             Name of the property within a row object that contains a record identifier value.                        </div>\r
96         </td>\r
97         <td class="msource">JsonReader</td>\r
98     </tr>\r
99         <tr class="config-row alt">\r
100         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
101         <td class="sig">\r
102         <a id="Ext.data.JsonReader-root"></a>\r
103             <b>root</b> : String            <div class="mdesc">\r
104                             name of the property which contains the Array of row objects.                        </div>\r
105         </td>\r
106         <td class="msource">JsonReader</td>\r
107     </tr>\r
108         <tr class="config-row">\r
109         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
110         <td class="sig">\r
111         <a id="Ext.data.JsonReader-successProperty"></a>\r
112             <b>successProperty</b> : String            <div class="mdesc">\r
113                             Name of the property from which to retrieve the success attribute used by forms.                        </div>\r
114         </td>\r
115         <td class="msource">JsonReader</td>\r
116     </tr>\r
117         <tr class="config-row alt expandable">\r
118         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
119         <td class="sig">\r
120         <a id="Ext.data.JsonReader-totalProperty"></a>\r
121             <b>totalProperty</b> : String            <div class="mdesc">\r
122                         <div class="short">Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the wh...</div>\r
123             <div class="long">\r
124                 Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the whole dataset is not passed in one go, but is being paged from the remote server.            </div>\r
125                         </div>\r
126         </td>\r
127         <td class="msource">JsonReader</td>\r
128     </tr>\r
129             </table>
130                 <a id="Ext.data.JsonReader-props"></a>
131         <h2>Public Properties</h2>
132                 <table cellspacing="0" class="member-table">
133             <tr>
134                 <th class="sig-header" colspan="2">Property</th>
135                 <th class="msource-header">Defined By</th>
136             </tr>
137                 <tr class="property-row expandable">\r
138         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
139         <td class="sig">\r
140         <a id="Ext.data.JsonReader-jsonData"></a>\r
141             <b>jsonData</b> : Object            <div class="mdesc">\r
142                         <div class="short">After any data loads, the raw JSON data is available for further custom processing.  If no data is
143 loaded or there is...</div>\r
144             <div class="long">\r
145                 After any data loads, the raw JSON data is available for further custom processing.  If no data is
146 loaded or there is a load exception this property will be undefined.            </div>\r
147                         </div>\r
148         </td>\r
149         <td class="msource">JsonReader</td>\r
150     </tr>\r
151         <tr class="property-row alt">\r
152         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
153         <td class="sig">\r
154         <a id="Ext.data.JsonReader-meta"></a>\r
155             <b>meta</b> : Mixed            <div class="mdesc">\r
156                             This JsonReader's metadata as passed to the constructor, or as passed in
157 the last data packet's <b><tt>metaData</tt></b> property.                        </div>\r
158         </td>\r
159         <td class="msource">JsonReader</td>\r
160     </tr>\r
161             </table>
162                 <a id="Ext.data.JsonReader-methods"></a>
163         <h2>Public Methods</h2>
164                 <table cellspacing="0" class="member-table">
165             <tr>
166                 <th class="sig-header" colspan="2">Method</th>
167                 <th class="msource-header">Defined By</th>
168             </tr>
169                 <tr class="method-row expandable">\r
170         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
171         <td class="sig">\r
172         <a id="Ext.data.JsonReader-JsonReader"></a>\r
173             <b>JsonReader</b>(&nbsp;<code>Object meta</code>, <code>Object recordType</code>&nbsp;)            <div class="mdesc">\r
174                         <div class="short">Create a new JsonReader</div>\r
175             <div class="long">\r
176                 Create a new JsonReader    <div class="mdetail-params">\r
177         <strong>Parameters:</strong>\r
178         <ul><li><code>meta</code> : Object<div class="sub-desc">Metadata configuration options.</div></li><li><code>recordType</code> : Object<div class="sub-desc">Either an Array of field definition objects as passed to
179 <a ext:cls="Ext.data.Record" ext:member="create" href="output/Ext.data.Record.html#create">Ext.data.Record.create</a>, or a <a ext:cls="Ext.data.Record" href="output/Ext.data.Record.html">Record</a> constructor created using <a ext:cls="Ext.data.Record" ext:member="create" href="output/Ext.data.Record.html#create">Ext.data.Record.create</a>.</div></li>        </ul>\r
180         <strong>Returns:</strong>\r
181         <ul>\r
182             <li><code></code></li>\r
183         </ul>\r
184     </div>\r
185                 </div>\r
186                         </div>\r
187         </td>\r
188         <td class="msource">JsonReader</td>\r
189     </tr>\r
190         <tr class="method-row alt expandable">\r
191         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
192         <td class="sig">\r
193         <a id="Ext.data.JsonReader-read"></a>\r
194             <b>read</b>(&nbsp;<code>Object response</code>&nbsp;) : Object            <div class="mdesc">\r
195                         <div class="short">
196 This method is only used by a DataProxy which has retrieved data from a remote server.</div>\r
197             <div class="long">\r
198                 
199 This method is only used by a DataProxy which has retrieved data from a remote server.    <div class="mdetail-params">\r
200         <strong>Parameters:</strong>\r
201         <ul><li><code>response</code> : Object<div class="sub-desc">The XHR object which contains the JSON data in its responseText.</div></li>        </ul>\r
202         <strong>Returns:</strong>\r
203         <ul>\r
204             <li><code>Object</code><div class="sub-desc">data A data block which is used by an Ext.data.Store object as a cache of Ext.data.Records.</div></li>\r
205         </ul>\r
206     </div>\r
207                 </div>\r
208                         </div>\r
209         </td>\r
210         <td class="msource">JsonReader</td>\r
211     </tr>\r
212         <tr class="method-row expandable">\r
213         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
214         <td class="sig">\r
215         <a id="Ext.data.JsonReader-readRecords"></a>\r
216             <b>readRecords</b>(&nbsp;<code>Object o</code>&nbsp;) : Object            <div class="mdesc">\r
217                         <div class="short">Create a data block containing Ext.data.Records from a JSON object.</div>\r
218             <div class="long">\r
219                 Create a data block containing Ext.data.Records from a JSON object.    <div class="mdetail-params">\r
220         <strong>Parameters:</strong>\r
221         <ul><li><code>o</code> : Object<div class="sub-desc">An object which contains an Array of row objects in the property specified
222 in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
223 which contains the total size of the dataset.</div></li>        </ul>\r
224         <strong>Returns:</strong>\r
225         <ul>\r
226             <li><code>Object</code><div class="sub-desc">data A data block which is used by an Ext.data.Store object as a cache of Ext.data.Records.</div></li>\r
227         </ul>\r
228     </div>\r
229                 </div>\r
230                         </div>\r
231         </td>\r
232         <td class="msource">JsonReader</td>\r
233     </tr>\r
234             </table>
235                 <a id="Ext.data.JsonReader-events"></a>
236         <h2>Public Events</h2>
237         <div class="no-members">This class has no public events.</div>
238         </div>