Ext.NET  5.3.0
.NET Component Framework for Enterprise Level Apps
Ext.Net.JsonReader Class Reference

The JSON Reader is used by a Proxy to read a server response that is sent back in JSON format. This usually happens as a result of loading a Store - for example we might create something like this: More...

Inheritance diagram for Ext.Net.JsonReader:
Ext.Net.AbstractReader Ext.Net.BaseItem Ext.Net.IAlias Ext.Net.IXObject Ext.Net.IBase Ext.Net.ArrayReader Ext.Net.ODataReader

Classes

class  Builder
 
class  Config
 

Public Member Functions

 JsonReader ()
 
JsonReader.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 JsonReader (Config config)
 
- Public Member Functions inherited from Ext.Net.AbstractReader
virtual void SetGroupRootProperty (string groupRootProperty)
 Sets the value of groupRootProperty. More...
 
virtual void SetSummaryRootProperty (string summaryRootProperty)
 Sets the value of summaryRootProperty. More...
 
virtual void SetMessageProperty (string messageProperty)
 Sets the value of messageProperty. More...
 
virtual void SetMessageProperty (JFunction messageProperty)
 Sets the value of messageProperty. More...
 
- Public Member Functions inherited from Ext.Net.BaseItem
virtual bool HasExplicitValue (string name)
 
void EnsureDataBind ()
 
virtual void Call (string name)
 
virtual void Call (string name, params object[] args)
 
virtual void AddScript (string script)
 
virtual void AddScript (string script, params object[] args)
 
virtual bool IsEmptyObject ()
 
Apply< T > (IApply config)
 
BaseItem Apply (object config)
 
virtual void LoadViewState (object state)
 
virtual object SaveViewState ()
 
virtual void TrackViewState ()
 
void SetDirty ()
 
virtual void DataBind ()
 

Static Public Member Functions

static implicit operator JsonReader (JsonReader.Config config)
 

Properties

override string InstanceOf [get]
 
override string Type [get]
 Alias More...
 
virtual string Record [get, set]
 The optional location within the JSON response that the record data itself can be found at. See the JsonReader intro docs for more details. This is not often needed and defaults to undefined. More...
 
virtual string MetaProperty [get, set]
 Name of the property from which to retrieve the metaData attribute. Defaults to: "metaData" More...
 
virtual bool PreserveRawData [get, set]
 The reader will keep a copy of the most recent request in the rawData property. For performance reasons, the data object for each record is used directly as the model data. This means that these objects may be modified and thus modify the raw data. To ensure the objects are copied, set this option to true. NB: This only applies to items that are read as part of the data array, any other metadata will not be modified: { "someOtherData": 1, // Won't be modified "root": [{}, {}, {}] // The objects here will be modified } More...
 
virtual bool UseSimpleAccessors [get, set]
 True to ensure that field names/mappings are treated as literals when reading values. Defalts to false. For example, by default, using the mapping "foo.bar.baz" will try and read a property foo from the root, then a property bar from foo, then a property baz from bar. Setting the simple accessors to true will read the property with the name "foo.bar.baz" direct from the root object. More...
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.AbstractReader
override string InstanceOf [get]
 
abstract string Type [get]
 Alias More...
 
virtual string GroupRootProperty [get, set]
 Name of the property from which to retrieve remote grouping summary information. More...
 
virtual string IDProperty [get, set]
 Name of the property within a row object that contains a record identifier value. Defaults to The id of the model. If an idProperty is explicitly specified it will override that of the one specified on the model More...
 
virtual bool ImplicitIncludes [get, set]
 True to automatically parse models nested within other models in a response object. See the Ext.data.reader.Reader intro docs for full explanation. Defaults to true. More...
 
virtual ? bool? KeepRawData [get, set]
 Determines if the Reader will keep raw data received from the server in the rawData property. While this might seem useful to do additional data processing, keeping raw data might cause adverse effects such as memory leaks. It is recommended to set keepRawData to false if you do not need the raw data. If you need to process data packet to extract additional data such as row summaries, it is recommended to use transform function for that purpose. Defaults to: true More...
 
virtual bool ReadRecordsOnFailure [get, set]
 True to read extract the records from a data packet even if the success property returns false. Defaults to: true More...
 
virtual string RootProperty [get, set]
 The name of the property which contains the Array of row objects. For JSON reader it's dot-separated list of property names. For XML reader it's a CSS selector. For array reader it's not applicable. By default the natural root of the data will be used. The root Json array, the root XML element, or the array. The data packet value for this property should be an empty array to clear the data or show no data. Defaults to: "" More...
 
virtual string SuccessProperty [get, set]
 Name of the property from which to retrieve the success attribute. Defaults to success. See Ext.data.proxy.Proxy.exception for additional information. More...
 
virtual string SummaryRootProperty [get, set]
 Name of the property from which to retrieve remote summary information. More...
 
virtual string TotalProperty [get, set]
 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. More...
 
virtual TransformFunction Transform [get]
 If a transform function is set, it will be invoked just before readRecords executes. It is passed the raw (deserialized) data object. The transform function returns a data object, which can be a modified version of the original data object, or a completely new data object. The transform can be a function, or an object with a 'fn' key and an optional 'scope' key. More...
 
virtual string TransformProxy [get]
 A proxy to render .Transform to client More...
 
virtual string TypeProperty [get, set]
 The name of the property in a node raw data block which indicates the type of the model to be created from that raw data. Useful for heterogenous trees. For example, hierarchical geographical data may look like this: { nodeType: 'Territory', name: 'EMEA', children: [{ nodeType: 'Country', name: 'United Kingdon', children: [{ nodeType: 'City', name: 'London' }] }] } More...
 
virtual string MessageProperty [get, set]
 The name of the property which contains a response message for exception handling. More...
 
virtual JFunction MessagePropertyFn [get, set]
 The name of the property which contains a response message for exception handling. More...
 
virtual string ModelName [get, set]
 The Ext.data.Model associated with this reader More...
 
string PropertyName [get]
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.BaseItem
virtual string InstanceOf [get]
 
ItemState State [get]
 
virtual DefaultValueMode DefaultValueMode [get, set]
 
virtual bool DesignMode [get]
 
bool AutoDataBind [get, set]
 
ResourceManager ResourceManager [get]
 
virtual Control Owner [get, set]
 The Owner Control for this Listener. More...
 
virtual bool IsDefault [get]
 Does this object currently represent it's default state. More...
 
bool IsTrackingViewState [get]
 
EventHandlerList Events [get]
 
EventHandler DataBinding
 
Control?? BindingContainer [get]
 
virtual ConfigItemCollection?? CustomConfig [get]
 Collection of custom js config More...
 
virtual ConfigOptionsCollection ConfigOptions [get]
 
virtual ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
System.Web.Mvc.HtmlHelper?? HtmlHelper [get, set]
 
- Properties inherited from Ext.Net.IXObject
ConfigOptionsCollection ConfigOptions [get]
 
ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
DefaultValueMode DefaultValueMode [get, set]
 
- Properties inherited from Ext.Net.IAlias
string PropertyName [get]
 

Additional Inherited Members

- Protected Member Functions inherited from Ext.Net.BaseItem
 BaseItem (Control owner)
 
 BaseItem ()
 
virtual void OwnerUpdate (Control owner)
 
virtual void OnDataBinding (EventArgs e)
 

Detailed Description

The JSON Reader is used by a Proxy to read a server response that is sent back in JSON format. This usually happens as a result of loading a Store - for example we might create something like this:

Ext.regModel('User', { fields: ['id', 'name', 'email'] });

var store = new Ext.data.Store({ model: 'User', proxy: { type: 'ajax', url : 'users.json', reader: { type: 'json' } } }); The example above creates a 'User' model. Models are explained in the Model docs if you're not already familiar with them.

We created the simplest type of JSON Reader possible by simply telling our Store's Proxy that we want a JSON Reader. The Store automatically passes the configured model to the Store, so it is as if we passed this instead:

reader: { type : 'json', model: 'User' } The reader we set up is ready to read data from our server - at the moment it will accept a response like this:

[ { "id": 1, "name": "Ed Spencer", "email": "ed@sencha.com" }, { "id": 2, "name": "Abe Elias", "email": "abe@sencha.com" } ] Reading other JSON formats

If you already have your JSON format defined and it doesn't look quite like what we have above, you can usually pass JsonReader a couple of configuration options to make it parse your format. For example, we can use the root configuration to parse data that comes back like this:

{ "users": [ { "id": 1, "name": "Ed Spencer", "email": "ed@sencha.com" }, { "id": 2, "name": "Abe Elias", "email": "abe@sencha.com" } ] } To parse this we just pass in a root configuration that matches the 'users' above:

reader: { type: 'json', root: 'users' } Sometimes the JSON structure is even more complicated. Document databases like CouchDB often provide metadata around each record inside a nested structure like this:

{ "total": 122, "offset": 0, "users": [ { "id": "ed-spencer-1", "value": 1, "user": { "id": 1, "name": "Ed Spencer", "email": "ed@sencha.com" } } ] } In the case above the record data is nested an additional level inside the "users" array as each "user" item has additional metadata surrounding it ('id' and 'value' in this case). To parse data out of each "user" item in the JSON above we need to specify the record configuration like this:

reader: { type : 'json', root : 'users', record: 'user' } Response metadata

The server can return additional data in its response, such as the total number of records and the success status of the response. These are typically included in the JSON response like this:

{ "total": 100, "success": true, "users": [ { "id": 1, "name": "Ed Spencer", "email": "ed@sencha.com" } ] } If these properties are present in the JSON response they can be parsed out by the JsonReader and used by the Store that loaded it. We can set up the names of these properties by specifying a final pair of configuration options:

reader: { type : 'json', root : 'users', totalProperty : 'total', successProperty: 'success' } These final options are not necessary to make the Reader work, but can be useful when the server needs to report an error or if it needs to indicate that there is a lot of data available of which only a subset is currently being returned.

Constructor & Destructor Documentation

◆ JsonReader() [1/2]

Ext.Net.JsonReader.JsonReader ( )
inline

◆ JsonReader() [2/2]

Ext.Net.JsonReader.JsonReader ( Config  config)
inline

Member Function Documentation

◆ operator JsonReader()

static implicit Ext.Net.JsonReader.operator JsonReader ( JsonReader.Config  config)
inlinestatic

◆ ToBuilder()

JsonReader.Builder Ext.Net.JsonReader.ToBuilder ( )
inline

◆ ToNativeBuilder()

override IControlBuilder Ext.Net.JsonReader.ToNativeBuilder ( )
inlinevirtual

Reimplemented from Ext.Net.BaseItem.

Reimplemented in Ext.Net.ODataReader.

Property Documentation

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.JsonReader.ConfigOptions
get

◆ InstanceOf

override string Ext.Net.JsonReader.InstanceOf
get

◆ MetaProperty

virtual string Ext.Net.JsonReader.MetaProperty
getset

Name of the property from which to retrieve the metaData attribute. Defaults to: "metaData"

◆ PreserveRawData

virtual bool Ext.Net.JsonReader.PreserveRawData
getset

The reader will keep a copy of the most recent request in the rawData property. For performance reasons, the data object for each record is used directly as the model data. This means that these objects may be modified and thus modify the raw data. To ensure the objects are copied, set this option to true. NB: This only applies to items that are read as part of the data array, any other metadata will not be modified: { "someOtherData": 1, // Won't be modified "root": [{}, {}, {}] // The objects here will be modified }

Defaults to false.

◆ Record

virtual string Ext.Net.JsonReader.Record
getset

The optional location within the JSON response that the record data itself can be found at. See the JsonReader intro docs for more details. This is not often needed and defaults to undefined.

◆ Type

override string Ext.Net.JsonReader.Type
getprotected

Alias

◆ UseSimpleAccessors

virtual bool Ext.Net.JsonReader.UseSimpleAccessors
getset

True to ensure that field names/mappings are treated as literals when reading values. Defalts to false. For example, by default, using the mapping "foo.bar.baz" will try and read a property foo from the root, then a property bar from foo, then a property baz from bar. Setting the simple accessors to true will read the property with the name "foo.bar.baz" direct from the root object.


The documentation for this class was generated from the following files: