extjs DataReader、JsonReader、XmlReader的构造方法

  extjs3.0帮助文档:

  DataReader( Object meta, Array/Object recordType )

  Create a new DataReader

  参数:

  meta : Object

  Metadata configuration options (implementation-specific).

  元数据配置选项(...-...)

  recordType : Array/Object

  Either an Array of Field definition objects

  任意一个Field定义的对象数组

  which will be passed to Ext.data.Record.create,

  作为对象传递给Ext.data.Record.create,

  or a Record constructor created using Ext.data.Record.create.

  或一个由Ext.data.Record.create创建的Record结构.

  返回:

  void

  内部关键js代码:

  Ext.data.DataReader = function(meta, recordType){

  this.meta = meta;

  this.recordType = Ext.isArray(recordType) ?

  Ext.data.Record.create(recordType) : recordType;

  this.buildExtractors();

  };

  ...略...

  rs.id = data[this.meta.idProperty];

  ...略...

  return (data && Ext.isObject(data) &&

  !Ext.isEmpty(data[this.meta.idProperty])) ? true : false;

  得出结论:

  a.recordType可以直接是一个Field结构的数组,由内部代码加上Ext.data.Record.create(...)。

  b.recordType可以是已经加上Ext.data.Record.create(...)的Field数组。

  c.meta中可以放属性:idProperty。

  extjs3.0帮助文档:

  XmlReader( Object meta, Object recordType )

  Create a new XmlReader.

  参数:

  meta : Object

  Metadata configuration options

  recordType : Object

  Either an Array of field definition objects as passed to Ext.data.Record.create,

  任意一个field定义的对象数组作为参数传递给Ext.data.Record.create

  or a Record constructor object created using Ext.data.Record.create.

  或者一个使用Ext.data.Record.create创建的Record结构对象。

  返回:

  void

  可以看出需要传两个obj进去,

  查看内部js代码

  Ext.data.JsonReader = function(meta, recordType){

  //如果没有meta,那创建一个Obj给meta。

  meta = meta || {};

  //把idProperty等添加到meta,如果它没有这些成员。

  Ext.applyIf(meta, {

  idProperty: 'id',

  successProperty: 'success',

  totalProperty: 'total'

  });

  //调用父类

  Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);

  };

  ...略...

  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';

  }

  可知:a.meta中可以有下列属性:idProperty、successProperty、totalProperty、fields、idPath、id、totalRecords、success。

  b.recordType可以为空,但要在meta中写fields。

  c.调用了父类构造,所以其他的跟父类一样。

  extjs3.0帮助文档:

  JsonReader( Object meta, Array/Object recordType )

  Create a new JsonReader

  Create a new JsonReader

  参数:

  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.

  返回:

  void

  查看内部js代码:

  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);

  };

  ...略...

  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);

  }

  可知:a.meta中可以有下列属性:idProperty、successProperty、totalProperty、root、fields

  b.recordType可以为空,但要在meta中写fields。

  c.调用了父类构造,所以其他的跟父类一样

  总结:...