Print Friendly

Class Ext.data.JsonReader

Package:Ext.data
Class:JsonReader
Extends:Ext.data.DataReader
Defined In:JsonReader.js
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.

Example code:

var RecordDef = Ext.data.Record.create([
    {name: 'name', mapping: 'name'},     // "mapping" property not needed if it's the same as "name"
    {name: 'occupation'}                 // This field will use "occupation" as the mapping.
]);
var myReader = new Ext.data.JsonReader({
    totalProperty: "results",    // The property which contains the total dataset size (optional)
    root: "rows",                // The property which contains an Array of row objects
    id: "id"                     // The property within each row object that provides an ID for the record (optional)
}, RecordDef);

This would consume a JSON file like this:

{ 'results': 2, 'rows': [
    { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
    { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
}

Properties   -  Methods   -  Events   -  Config Options

Public Properties

Property Defined By
  jsonData : Object JsonReader
After any data loads, the raw JSON data is available for further custom processing.

Public Methods

Method Defined By
  JsonReaderObject meta, Object recordType ) JsonReader
Create a new JsonReader
  readObject response ) : Object JsonReader
This method is only used by a DataProxy which has retrieved data from a remote server.
  readRecordsObject o ) : Object JsonReader
Create a data block containing Ext.data.Records from an XML document.

Public Events

This class has no public events.

Config Options

Config Options Defined By
  id : String JsonReader
Name of the property within a row object that contains a record identifier value.
  root : String JsonReader
name of the property which contains the Array of row objects.
  successProperty : String JsonReader
Name of the property from which to retrieve the success attribute used by forms.
  totalProperty : String JsonReader
Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the wh...

Property Details

jsonData

public Object jsonData
After any data loads, the raw JSON data is available for further custom processing.
This property is defined by JsonReader.

Constructor Details

JsonReader

public function JsonReader( Object meta, Object recordType )
Create a new JsonReader
Parameters:

Method Details

read

public function read( Object response )
This method is only used by a DataProxy which has retrieved data from a remote server.
Parameters:
  • response : Object
    The XHR object which contains the JSON data in its responseText.
Returns:
  • Object
    data A data block which is used by an Ext.data.Store object as a cache of Ext.data.Records.
This method is defined by JsonReader.

readRecords

public function readRecords( Object o )
Create a data block containing Ext.data.Records from an XML document.
Parameters:
  • o : Object
    An object which contains an Array of row objects in the property specified in the config as 'root, and optionally a property, specified in the config as 'totalProperty' which contains the total size of the dataset.
Returns:
  • Object
    data A data block which is used by an Ext.data.Store object as a cache of Ext.data.Records.
This method is defined by JsonReader.

Config Details

id

id : String
Name of the property within a row object that contains a record identifier value.
This config option is defined by JsonReader.

root

root : String
name of the property which contains the Array of row objects.
This config option is defined by JsonReader.

successProperty

successProperty : String
Name of the property from which to retrieve the success attribute used by forms.
This config option is defined by JsonReader.

totalProperty

totalProperty : String
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.
This config option is defined by JsonReader.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.