Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / output / Ext.data.reader.Reader.js
1 Ext.data.JsonP.Ext_data_reader_Reader({
2   "tagname": "class",
3   "name": "Ext.data.reader.Reader",
4   "doc": "<p>Readers are used to interpret data to be loaded into a <a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">Model</a> instance or a <a href=\"#/api/Ext.data.Store\" rel=\"Ext.data.Store\" class=\"docClass\">Store</a>\n- usually in response to an AJAX request. This is normally handled transparently by passing some configuration to either the \n<a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">Model</a> or the <a href=\"#/api/Ext.data.Store\" rel=\"Ext.data.Store\" class=\"docClass\">Store</a> in question - see their documentation for further details.</p>\n\n\n\n\n<p><u>Loading Nested Data</u></p>\n\n\n\n\n<p>Readers have the ability to automatically load deeply-nested data objects based on the <a href=\"#/api/Ext.data.Association\" rel=\"Ext.data.Association\" class=\"docClass\">associations</a>\nconfigured on each Model. Below is an example demonstrating the flexibility of these associations in a fictional CRM system which\nmanages a User, their Orders, OrderItems and Products. First we'll define the models:\n\n<pre><code>Ext.define(\"User\", {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'name'\n    ],\n\n    hasMany: {model: 'Order', name: 'orders'},\n\n    proxy: {\n        type: 'rest',\n        url : 'users.json',\n        reader: {\n            type: 'json',\n            root: 'users'\n        }\n    }\n});\n\nExt.define(\"Order\", {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'total'\n    ],\n\n    hasMany  : {model: 'OrderItem', name: 'orderItems', associationKey: 'order_items'},\n    belongsTo: 'User'\n});\n\nExt.define(\"OrderItem\", {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'price', 'quantity', 'order_id', 'product_id'\n    ],\n\n    belongsTo: ['Order', {model: 'Product', associationKey: 'product'}]\n});\n\nExt.define(\"Product\", {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'name'\n    ],\n\n    hasMany: 'OrderItem'\n});\n</code></pre>\n\n<p>This may be a lot to take in - basically a User has many Orders, each of which is composed of several OrderItems. Finally,\neach OrderItem has a single Product. This allows us to consume data like this:</p>\n\n<pre><code>{\n    \"users\": [\n        {\n            \"id\": 123,\n            \"name\": \"Ed\",\n            \"orders\": [\n                {\n                    \"id\": 50,\n                    \"total\": 100,\n                    \"order_items\": [\n                        {\n                            \"id\"      : 20,\n                            \"price\"   : 40,\n                            \"quantity\": 2,\n                            \"product\" : {\n                                \"id\": 1000,\n                                \"name\": \"MacBook Pro\"\n                            }\n                        },\n                        {\n                            \"id\"      : 21,\n                            \"price\"   : 20,\n                            \"quantity\": 3,\n                            \"product\" : {\n                                \"id\": 1001,\n                                \"name\": \"iPhone\"\n                            }\n                        }\n                    ]\n                }\n            ]\n        }\n    ]\n}\n</code></pre>\n\n<p>The JSON response is deeply nested - it returns all Users (in this case just 1 for simplicity's sake), all of the Orders\nfor each User (again just 1 in this case), all of the OrderItems for each Order (2 order items in this case), and finally\nthe Product associated with each OrderItem. Now we can read the data and use it as follows:\n\n<pre><code>var store = new Ext.data.Store({\n    model: \"User\"\n});\n\nstore.load({\n    callback: function() {\n        //the user that was loaded\n        var user = store.first();\n\n        console.log(\"Orders for \" + user.get('name') + \":\")\n\n        //iterate over the Orders for each User\n        user.orders().each(function(order) {\n            console.log(\"Order ID: \" + order.getId() + \", which contains items:\");\n\n            //iterate over the OrderItems for each Order\n            order.orderItems().each(function(orderItem) {\n                //we know that the Product data is already loaded, so we can use the synchronous getProduct\n                //usually, we would use the asynchronous version (see <a href=\"#/api/Ext.data.BelongsToAssociation\" rel=\"Ext.data.BelongsToAssociation\" class=\"docClass\">Ext.data.BelongsToAssociation</a>)\n                var product = orderItem.getProduct();\n\n                console.log(orderItem.get('quantity') + ' orders of ' + product.get('name'));\n            });\n        });\n    }\n});\n</code></pre>\n\n<p>Running the code above results in the following:</p>\n\n<pre><code>Orders for Ed:\nOrder ID: 50, which contains items:\n2 orders of MacBook Pro\n3 orders of iPhone\n</code></pre>\n\n",
5   "extends": "Object",
6   "mixins": [
7
8   ],
9   "alternateClassNames": [
10     "Ext.data.Reader",
11     "Ext.data.DataReader"
12   ],
13   "xtype": null,
14   "author": "Ed Spencer",
15   "docauthor": null,
16   "singleton": false,
17   "private": false,
18   "cfg": [
19     {
20       "tagname": "cfg",
21       "name": "idProperty",
22       "member": "Ext.data.reader.Reader",
23       "type": "String",
24       "doc": "<p>Name of the property within a row object\nthat contains a record identifier value.  Defaults to <tt>The id of the model</tt>.\nIf an idProperty is explicitly specified it will override that of the one specified\non the model</p>\n",
25       "private": false,
26       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
27       "linenr": 153,
28       "html_filename": "Reader.html",
29       "href": "Reader.html#Ext-data-reader-Reader-cfg-idProperty",
30       "shortDoc": "Name of the property within a row object\nthat contains a record identifier value.  Defaults to The id of the model.\nI..."
31     },
32     {
33       "tagname": "cfg",
34       "name": "implicitIncludes",
35       "member": "Ext.data.reader.Reader",
36       "type": "Boolean",
37       "doc": "<p>True to automatically parse models nested within other models in a response\nobject. See the <a href=\"#/api/Ext.data.reader.Reader\" rel=\"Ext.data.reader.Reader\" class=\"docClass\">Ext.data.reader.Reader</a> intro docs for full explanation. Defaults to true.</p>\n",
38       "private": false,
39       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
40       "linenr": 190,
41       "html_filename": "Reader.html",
42       "href": "Reader.html#Ext-data-reader-Reader-cfg-implicitIncludes",
43       "shortDoc": "True to automatically parse models nested within other models in a response\nobject. See the Ext.data.reader.Reader in..."
44     },
45     {
46       "tagname": "cfg",
47       "name": "messageProperty",
48       "member": "Ext.data.reader.Reader",
49       "type": "String",
50       "doc": "<p>The name of the property which contains a response message.\nThis property is optional.</p>\n",
51       "private": false,
52       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
53       "linenr": 185,
54       "html_filename": "Reader.html",
55       "href": "Reader.html#Ext-data-reader-Reader-cfg-messageProperty"
56     },
57     {
58       "tagname": "cfg",
59       "name": "root",
60       "member": "Ext.data.reader.Reader",
61       "type": "String",
62       "doc": "<p><b>Required</b>.  The name of the property\nwhich contains the Array of row objects.  Defaults to <tt>undefined</tt>.\nAn exception will be thrown if the root property is undefined. The data\npacket value for this property should be an empty array to clear the data\nor show no data.</p>\n",
63       "private": false,
64       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
65       "linenr": 176,
66       "html_filename": "Reader.html",
67       "href": "Reader.html#Ext-data-reader-Reader-cfg-root",
68       "shortDoc": "Required.  The name of the property\nwhich contains the Array of row objects.  Defaults to undefined.\nAn exception wil..."
69     },
70     {
71       "tagname": "cfg",
72       "name": "successProperty",
73       "member": "Ext.data.reader.Reader",
74       "type": "String",
75       "doc": "<p>Name of the property from which to\nretrieve the success attribute. Defaults to <tt>success</tt>.  See\n<a href=\"#/api/Ext.data.proxy.Proxy\" rel=\"Ext.data.proxy.Proxy\" class=\"docClass\">Ext.data.proxy.Proxy</a>.<a href=\"#/api/Ext.data.proxy.Proxy--exception\" rel=\"Ext.data.proxy.Proxy--exception\" class=\"docClass\">exception</a>\nfor additional information.</p>\n",
76       "private": false,
77       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
78       "linenr": 168,
79       "html_filename": "Reader.html",
80       "href": "Reader.html#Ext-data-reader-Reader-cfg-successProperty",
81       "shortDoc": "Name of the property from which to\nretrieve the success attribute. Defaults to success.  See\nExt.data.proxy.Proxy.exc..."
82     },
83     {
84       "tagname": "cfg",
85       "name": "totalProperty",
86       "member": "Ext.data.reader.Reader",
87       "type": "String",
88       "doc": "<p>Name of the property from which to\nretrieve the total number of records in the dataset. This is only needed\nif the whole dataset is not passed in one go, but is being paged from\nthe remote server.  Defaults to <tt>total</tt>.</p>\n",
89       "private": false,
90       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
91       "linenr": 160,
92       "html_filename": "Reader.html",
93       "href": "Reader.html#Ext-data-reader-Reader-cfg-totalProperty",
94       "shortDoc": "Name of the property from which to\nretrieve the total number of records in the dataset. This is only needed\nif the wh..."
95     }
96   ],
97   "method": [
98     {
99       "tagname": "method",
100       "name": "Reader",
101       "member": "Ext.data.reader.Reader",
102       "doc": "\n",
103       "params": [
104         {
105           "type": "Object",
106           "name": "config",
107           "doc": "<p>Optional config object</p>\n",
108           "optional": false
109         }
110       ],
111       "return": {
112         "type": "void",
113         "doc": "\n"
114       },
115       "private": false,
116       "static": false,
117       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
118       "linenr": 1,
119       "html_filename": "Reader.html",
120       "href": "Reader.html#Ext-data-reader-Reader-method-constructor",
121       "shortDoc": "\n"
122     },
123     {
124       "tagname": "method",
125       "name": "getResponseData",
126       "member": "Ext.data.reader.Reader",
127       "doc": "<p>Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemented by each subclass</p>\n",
128       "params": [
129         {
130           "type": "Object",
131           "name": "response",
132           "doc": "<p>The responce object</p>\n",
133           "optional": false
134         }
135       ],
136       "return": {
137         "type": "Object",
138         "doc": "<p>The useful data from the response</p>\n"
139       },
140       "private": false,
141       "static": false,
142       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
143       "linenr": 458,
144       "html_filename": "Reader.html",
145       "href": "Reader.html#Ext-data-reader-Reader-method-getResponseData",
146       "shortDoc": "Takes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemen..."
147     },
148     {
149       "tagname": "method",
150       "name": "read",
151       "member": "Ext.data.reader.Reader",
152       "doc": "<p>Reads the given response object. This method normalizes the different types of response object that may be passed\nto it, before handing off the reading of records to the <a href=\"#/api/Ext.data.reader.Reader-method-readRecords\" rel=\"Ext.data.reader.Reader-method-readRecords\" class=\"docClass\">readRecords</a> function.</p>\n",
153       "params": [
154         {
155           "type": "Object",
156           "name": "response",
157           "doc": "<p>The response object. This may be either an XMLHttpRequest object or a plain JS object</p>\n",
158           "optional": false
159         }
160       ],
161       "return": {
162         "type": "Ext.data.ResultSet",
163         "doc": "<p>The parsed ResultSet object</p>\n"
164       },
165       "private": false,
166       "static": false,
167       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
168       "linenr": 226,
169       "html_filename": "Reader.html",
170       "href": "Reader.html#Ext-data-reader-Reader-method-read",
171       "shortDoc": "Reads the given response object. This method normalizes the different types of response object that may be passed\nto ..."
172     },
173     {
174       "tagname": "method",
175       "name": "readRecords",
176       "member": "Ext.data.reader.Reader",
177       "doc": "<p>Abstracts common functionality used by all Reader subclasses. Each subclass is expected to call\nthis function before running its own logic and returning the <a href=\"#/api/Ext.data.ResultSet\" rel=\"Ext.data.ResultSet\" class=\"docClass\">Ext.data.ResultSet</a> instance. For most\nReaders additional processing should not be needed.</p>\n",
178       "params": [
179         {
180           "type": "Mixed",
181           "name": "data",
182           "doc": "<p>The raw data object</p>\n",
183           "optional": false
184         }
185       ],
186       "return": {
187         "type": "Ext.data.ResultSet",
188         "doc": "<p>A ResultSet object</p>\n"
189       },
190       "private": false,
191       "static": false,
192       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
193       "linenr": 246,
194       "html_filename": "Reader.html",
195       "href": "Reader.html#Ext-data-reader-Reader-method-readRecords",
196       "shortDoc": "Abstracts common functionality used by all Reader subclasses. Each subclass is expected to call\nthis function before ..."
197     }
198   ],
199   "property": [
200     {
201       "tagname": "property",
202       "name": "rawData",
203       "member": "Ext.data.reader.Reader",
204       "type": "Mixed",
205       "doc": "<p>The raw data object that was last passed to readRecords. Stored for further processing if needed</p>\n",
206       "private": false,
207       "static": false,
208       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
209       "linenr": 266,
210       "html_filename": "Reader.html",
211       "href": "Reader.html#Ext-data-reader-Reader-property-rawData"
212     }
213   ],
214   "event": [
215
216   ],
217   "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/reader/Reader.js",
218   "linenr": 1,
219   "html_filename": "Reader.html",
220   "href": "Reader.html#Ext-data-reader-Reader",
221   "cssVar": [
222
223   ],
224   "cssMixin": [
225
226   ],
227   "component": false,
228   "superclasses": [
229
230   ],
231   "subclasses": [
232     "Ext.data.reader.Json",
233     "Ext.data.reader.Xml"
234   ],
235   "mixedInto": [
236
237   ],
238   "allMixins": [
239
240   ]
241 });