Reader JsonReader
Package: | Ext.data |
Defined In: | JsonReader.js |
Class: | JsonReader |
Subclasses: | ArrayReader |
Extends: | Reader |
Data reader class to create an Array of Ext.data.Model objects from a JSON packet based on mappings in a provided Ext.data.Model constructor.
Example code:
var myReader = new Ext.data.Store({
proxy: {
type: 'ajax',
reader: {
type: 'json',
// metadata configuration options:
idProperty: 'id'
root: 'rows',
totalProperty: 'results'
}
},
// the fields config option will internally create an Ext.data.Model
// 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: 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' },
...
]
}
Config Options | Defined By | |
---|---|---|
idProperty : String Name of the property within a row object
that contains a record identifier value. Defaults to id | Reader | |
implicitIncludes : Boolean True to automatically parse models nested within other models in a JSON
object. See JsonReader intro docs for full ex... True to automatically parse models nested within other models in a JSON
object. See JsonReader intro docs for full explanation. Defaults to true. | Reader | |
root : String Required. The name of the property
which contains the Array of row objects. Defaults to undefined.
An exception wil... Required. The name of the property
which contains the Array of row objects. Defaults to undefined.
An exception will be thrown if the root property is undefined. The data
packet value for this property should be an empty array to clear the data
or show no data. | Reader | |
successProperty : String Name of the property from which to
retrieve the success attribute. Defaults to success. See
Ext.data.DataProxy.excep... Name of the property from which to
retrieve the success attribute. Defaults to success. See
Ext.data.DataProxy.exception
for additional information. | Reader | |
totalProperty : String Name of the property from which to
retrieve the total number of records in the dataset. This is only needed
if the wh... 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. Defaults to total. | Reader |
Property | Defined By | |
---|---|---|
jsonData : Mixed DEPRECATED - will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead | JsonReader | |
rawData : Mixed The raw data object that was last passed to readRecords. Stored for further processing if needed | Reader |
Method | Defined By | |
---|---|---|
getResponseData( Object response )
:
ObjectTakes a raw response object (as passed to this.read) and returns the useful data segment of it. This must be implemen... 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 Parameters:
| Reader | |
read( Object response )
:
Ext.data.ResultSetReads the given response object. This method normalizes the different types of response object that may be passed
to ... Reads the given response object. This method normalizes the different types of response object that may be passed
to it, before handing off the reading of records to the readRecords function. Parameters:
| Reader | |
readRecords( Object data )
:
Ext.data.ResultSetReads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to
retrieve meta da... Reads a JSON object and returns a ResultSet. Uses the internal getTotal and getSuccess extractors to
retrieve meta data from the response, and extractData to turn the JSON data into model instances. Parameters:
| JsonReader |