| Package: | Ext.grid |
| Defined In: | .js |
| Class: | |
| Extends: | Ext.data.DataReader |
Json格式的数据读取器,继承自数据读取器。它基于Ext.data.Record提供的构造器映射方式,将json response对象构建成Ext.data.Record对象的数组
示例代码:
var Employee = 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)
}, Employee);
This would consume a JSON file like this:
{ 'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
{ 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
}
It is possible to change a JsonReader's metadata at any time by including a MetaData property in the data object. If this is detected in the object, a Ext.data.Store Store object using this Reader will fire its Ext.data.Store#metachange metachange event.
The MetaData property may contain any of the configuration options for this class. Additionally, it may contain a fields property which the JsonReader will use that as an argument to Ext.data.Record.create to configure the layout of the Records which it will produce.
Using the MetaData property, and the Store's Ext.data.Store#metachange metachange event, it is possible to have a Store-driven control initialize itself. The metachange event handler may interrogate the MetaData property (which may contain any user-defined properties needed) and the MetaData.fields property to perform any configuration required.
To use this facility to send the same data as the above example 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 as well as the data:
{
'metaData': {
totalProperty: 'results',
root: 'rows',
id: 'id',
fields: [
{name: 'name'},
{name: 'occupation'} ]
},
'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
{ 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
}
@cfg {String} totalProperty 一属性名,通过该属性可以得到数据集中记录总条数
该属性仅当整个数据集一口气传过来时需要.而不是被远程主机分过页的
@cfg {String} 属性名,通过该属性能得到被forms使用的成功属性
@cfg {String} 一属性的名字,该属性包含一行对象的数组
@cfg {String} 行对象的一属性的名字,该属性包含记录的标识值
| 属性 | 定义者 | |
|---|---|---|
|
this: Object
数据加载完毕后,此属性保存了原始JSON数据以便进一步的使用。如果未成...
数据加载完毕后,此属性保存了原始JSON数据以便进一步的使用。如果未成功加载数据或发生加载的异常该属性就是undefined。
|
JsonReader | |
|
meta: Mixed
This DataReader's configured metada...
This DataReader's configured metadata as passed to the constructor.
|
DataReader | |