X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..92c2b89db26be16707f4a805d3303ab2531006e1:/docs/output/Ext.data.JsonReader.html diff --git a/docs/output/Ext.data.JsonReader.html b/docs/output/Ext.data.JsonReader.html index 2894b555..2303cb68 100644 --- a/docs/output/Ext.data.JsonReader.html +++ b/docs/output/Ext.data.JsonReader.html @@ -1,84 +1,110 @@ -
DataReader JsonReader
Package: | Ext.data |
Defined In: | JsonReader.js |
Class: | JsonReader |
Subclasses: | ArrayReader |
Extends: | DataReader |
Data reader class to create an Array of Ext.data.Record objects from a JSON response -based on mappings in a provided Ext.data.Record constructor.
+DataReader JsonReader
Package: | Ext.data |
Defined In: | JsonReader.js |
Class: | JsonReader |
Subclasses: | ArrayReader |
Extends: | DataReader |
Data reader class to create an Array of Ext.data.Record objects +from a JSON packet based on mappings in a provided Ext.data.Record +constructor.
Example code:
-var Employee = Ext.data.Record.create([
- {name: 'firstname'}, // map the Record's "firstname" field to the row object's key of the same name
- {name: 'job', mapping: 'occupation'} // map the Record's "job" field to the row object's "occupation" key
-]);
-var myReader = new Ext.data.JsonReader(
- { // The metadata property, with configuration options:
- totalProperty: "results", // the property which contains the total dataset size (optional)
- root: "rows", // the property which contains an Array of record data objects
- idProperty: "id" // the property within each row object that provides an ID for the record (optional)
- },
- Employee // Ext.data.Record constructor that provides mapping for JSON object
-);
+var myReader = new Ext.data.JsonReader({
+ // metadata configuration options:
+ idProperty: 'id'
+ root: 'rows',
+ totalProperty: 'results',
+ Ext.data.DataReader.messageProperty: "msg" // The element within the response that provides a user-feedback message (optional)
+
+ // the fields config option will internally create an Ext.data.Record
+ // constructor that provides mapping for reading the record data objects
+ fields: [
+ // map Record's 'firstname' field to data object's key of same name
+ {name: 'name'},
+ // map Record's 'job' field to data object's 'occupation' key
+ {name: 'job', mapping: 'occupation'}
+ ]
+});
This would consume a JSON data object of the form:
{
- results: 2, // Reader's configured totalProperty
- rows: [ // Reader's configured root
- { id: 1, firstname: 'Bill', occupation: 'Gardener' }, // a row object
- { id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' } // another row object
+ results: 2000, // Reader's configured totalProperty
+ rows: [ // Reader's configured root
+ // record data objects:
+ { id: 1, firstname: 'Bill', occupation: 'Gardener' },
+ { id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
+ ...
]
}
Automatic configuration using metaData
-It is possible to change a JsonReader's metadata at any time by including a metaData -property in the JSON data object. If the JSON data object has a metaData property, a -Store object using this Reader will reconfigure itself to use the newly provided -field definition and fire its metachange event. The metachange event -handler may interrogate the metaData property to perform any configuration required. -Note that reconfiguring a Store potentially invalidates objects which may refer to Fields or Records -which no longer exist.
-The metaData property in the JSON data object may contain:
-To use this facility to send the same data as the example above (without having to code the creation -of the Record constructor), you would create the JsonReader like this:
var myReader = new Ext.data.JsonReader();
-The first data packet from the server would configure the reader by containing a -metaData property and the data. For example, the JSON data object might take -the form:
-{
+It is possible to change a JsonReader's metadata at any time by including
+a metaData property in the JSON data object. If the JSON data
+object has a metaData property, a Store
+object using this Reader will reconfigure itself to use the newly provided
+field definition and fire its metachange
+event. The metachange event handler may interrogate the metaData
+property to perform any configuration required.
+Note that reconfiguring a Store potentially invalidates objects which may
+refer to Fields or Records which no longer exist.
+To use this facility you would create the JsonReader like this:
var myReader = new Ext.data.JsonReader();
+The first data packet from the server would configure the reader by
+containing a metaData property and the data. For
+example, the JSON data object might take the form:
{
metaData: {
- idProperty: 'id',
- root: 'rows',
- totalProperty: 'results',
- fields: [
- {name: 'name'},
- {name: 'job', mapping: 'occupation'}
+ "idProperty": "id",
+ "root": "rows",
+ "totalProperty": "results"
+ "successProperty": "success",
+ "fields": [
+ {"name": "name"},
+ {"name": "job", "mapping": "occupation"}
],
- sortInfo: {field: 'name', direction:'ASC'}, // used by store to set its sortInfo
- foo: 'bar' // custom property
+ // used by store to set its sortInfo
+ "sortInfo":{
+ "field": "name",
+ "direction": "ASC"
+ },
+ // paging data (if applicable)
+ "start": 0,
+ "limit": 2,
+ // custom property
+ "foo": "bar"
},
- results: 2,
- rows: [ // an Array
- { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
- { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' }
+ // Reader's configured successProperty
+ "success": true,
+ // Reader's configured totalProperty
+ "results": 2000,
+ // Reader's configured root
+ // (this data simulates 2 results per page)
+ "rows": [ // *Note: this must be an Array
+ { "id": 1, "name": "Bill", "occupation": "Gardener" },
+ { "id": 2, "name": "Ben", "occupation": "Horticulturalist" }
]
-}
Config Options | Defined By | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fields : Array/Object Either an Array of Field definition objects (which
+}
+ The metaData property in the JSON data object should contain: +
Config Options
Public Properties
Public Properties
Public Methods
|