Home  >  Article  >  Web Front-end  >  Construction methods of extjs DataReader, JsonReader, and XmlReader_extjs

Construction methods of extjs DataReader, JsonReader, and XmlReader_extjs

WBOY
WBOYOriginal
2016-05-16 18:42:161064browse

extjs3.0 help documentation:
DataReader(Object meta, Array/Object recordType)
Create a new DataReader
Parameters:

meta: Object
Metadata configuration options (implementation-specific ).
Metadata configuration options (...-...)
recordType : Array/Object
Either an Array of Field definition objects
Any object array defined by Field
which will be passed to Ext.data.Record.create,
as an object passed to Ext.data.Record.create,
or a Record constructor created using Ext.data.Record.create. Record structure created by Ext.data.Record.create.
Returns:
void

Internal key js code:
Ext.data.DataReader = function(meta, recordType){
this.meta = meta;
this.recordType = Ext.isArray(recordType) ?
Ext.data.Record.create(recordType) : recordType;
this.buildExtractors();
} ;
... slightly...
rs.id = data[this.meta.idProperty];
... slightly...
return (data && Ext.isObject(data) &&
!Ext.isEmpty(data[this.meta.idProperty])) ? true : false;

Conclusion:
a.recordType can be directly an array of Field structure, consisting of Internal code plus Ext.data.Record.create(...).
b.recordType can be a Field array that has been added with Ext.data.Record.create(...).
Attributes can be placed in c.meta: idProperty.




extjs3.0 help documentation:
XmlReader( Object meta, Object recordType )
Create a new XmlReader.
Parameters:
meta: Object
Metadata configuration options
recordType : Object
Either an Array of field definition objects as passed to Ext.data.Record.create,
An array of field definition objects as passed to Ext. data.Record.create
or a Record constructor object created using Ext.data.Record.create.
or a Record constructor object created using Ext.data.Record.create.
Return:
void

It can be seen that two objs need to be passed in,

View the internal js code
Ext.data.JsonReader = function(meta, recordType) {
//If there is no meta, create an Obj for meta.
meta = meta || {};
//Add idProperty, etc. to meta, if it does not have these members.
Ext.applyIf(meta, {
idProperty: 'id',
successProperty: 'success',
totalProperty: 'total'
});
//Call the parent class
Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);
};
...omitted...
var sid = this. meta.idPath || this.meta.id;
var totalRecords = 0, success = true;
if(this.meta.totalRecords){
totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
}
if(this.meta.success){
var sv = q.selectValue(this.meta.success, root, true);
success = sv != = false && sv !== 'false';
}
It can be seen that: a.meta can have the following properties: idProperty, successProperty, totalProperty, fields, idPath, id, totalRecords, success.
b.recordType can be empty, but fields must be written in meta.
c. The parent class constructor is called, so everything else is the same as the parent class.


extjs3.0 help document:
JsonReader(Object meta, Array/Object recordType)
Create a new JsonReader
Create a new JsonReader
Parameters:
meta : Object
Metadata configuration options.
recordType : Array/Object
Either an Array of Field definition objects
(which will be passed to Ext.data.Record.create,
or a Record constructor created from Ext.data.Record.create.
Returns:
void

View internal js code:
Ext.data.JsonReader = function(meta, recordType){
meta = meta || {};
Ext.applyIf(meta, {
idProperty: 'id',
successProperty: 'success',
totalProperty: 'total' });
Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);
};
...omitted...
if (Ext.isEmpty(o [this.meta.root])) {
throw new Ext.data.JsonReader.Error('root-emtpy', this.meta.root);
}
else if (o[this. meta.root] === undefined) {
throw new Ext.data.JsonReader.Error('root-undefined-response', this.meta.root);
}

It can be seen that: a.meta can have the following properties: idProperty, successProperty, totalProperty, root, fields
b.recordType can be empty, but fields must be written in meta.
c. The parent class constructor is called, so everything else is the same as the parent class

Summary:...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn