Ext中数据读取器Ext.data.DataReader的学习

1:Ext.data.DataReader

      数据读取器,它是所有读取数据的基类,主要功能就是将数据代理从远程服务器或者本地数据请求返回的异构数据按照规定的数据记录类型解析成Ext Js的Record数据集类型,并且保存到store的数据集中。

      在Ext Js中还提供了读取二维数组、JSON数据以及XML等读取器。


2:Ext.data.ArrayReader

      ArrayReader则是读取数据的读取器,主要用来读取二维数组,然后生成对应的record,默认情况下是按列顺序读取二维数组,不过还可以考虑使用mapping指定record与原始数组对应的列号

    ArrayReader(Object meta, Object recordType)中的第一个参数是指示使用哪个字段做id,第二个参数与record对象的create方法的参数一样,都有config对象数组。从proxy中读取的数据需要进行解析,这些数据转换成Record数组后才能提供给Ext.data.Store使用。

   ArrayReader的用法很简单,缺点是不支持分页,代码如下:

    

var data = [
         {'id1', 'name1', 'descn1'},
         {'id2', 'name2', 'descn2'}
        ];
     var reader = new Ext.data.ArrayReader({
          id: 1
         }, [
            {name: 'name', mapping: 1},
            {name: 'descn', mapping: 2}, 
            {name: 'id', mapping: 0}
         ]);

3:Ext.data.JsonReader

与数组相比,json的特点是支持分页。

var jsonData = {

      id: 0,

     totalProperty: 2,

     successProperty: true,

     root: [

           {id: '1', name: 'name1', descn: 'descn1'},

          {id: '2', name: 'name2', descn: 'descn2'},

     ]

};

可以使用totalProperty参数表示数组的总量,successProperty参数是可选的,可以用它判断当前请求是否执行成功,进而判断是否进行数据加载,在不希望JsonReader处理响应数据时,可以把successProperty设置为false,代码如下:

    var reader = new Ext.data.JsonReader({

              successProperty: "successProperty",

              totalProperty: "totalPropert",

              root: "root",

               id: "id"

   }, [

       {name: 'id', mapping: 'id'},

       {name: 'name', mapping: 'name'},

        {name: 'descn', mapping: 'descn'},

]);

4:Ext.data.XmlReader

   它用于读取XML文件格式的数据,并把数据转换为record对象类型,在使用它时,它的配置和JsonReader是不一样的,XmlReader的配置方式是id、success、record和totalRecords,JsonReader配置方式则是id、root、successProperty、totalProperty,其中,totalRecords表示从totolRecords标签里获得后台数据的总数,record表示XML中放在record标签里要显示的数据,success用来判断操作是否成功,id为这次返回的id,因为XML中的标签和reader里需要的名字是相同的,所以简化了配置,将

   

[{name: 'id'},
 {name: 'name'},
 {name: 'descn'},
 ]

直接写成了:

 

['id', 'name', 'descn']

简单示例如下:

 

var Employee = Ext.data.Record.create([
   {name: 'name', mapping: 'name'},     // "mapping" property not needed if it is the same as "name"
   {name: 'occupation'}                 // This field will use "occupation" as the mapping.
]);
var myReader = new Ext.data.XmlReader({
   totalProperty: "results", // The element which contains the total dataset size (optional)
   record: "row",           // The repeated element which contains row information
   idProperty: "id"         // The element within the row that provides an ID for the record (optional)
   messageProperty: "msg"   // The element within the response that provides a user-feedback message (optional)
}, Employee);

XML文件为:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
 <results>2</results>
 <row>
   <id>1</id>
   <name>Bill</name>
   <occupation>Gardener</occupation>
 </row>
 <row>
   <id>2</id>
   <name>Ben</name>
   <occupation>Horticulturalist</occupation>
 </row>
</dataset>


可以读写Ext2,以Ext2方式挂载Ext3文件系统(不支持Ext3日志),不支持文! It provides Windows NT4.0/2000/XP/2003/Vista/2008 with full access to Linux Ext2 volumes (read access andwrite access). This may be useful if you have installed both Windows and Linux as a dual boot environment on your computer. What features are supported? Complete reading and writing access to files and directories of volumes with theExt2 orExt3 file system. Supports features which are specific to the I/O-system of Windows: Byte Range Locks, Directory Notfication (so the Explorer updates the view of a directory on changes within that directory), Oplocks (so SMB clients are able to cache the content of files). Allows Windows to run with paging files on Ext2 volumes. UTF-8 encoded file names are supported. The driver treats files with file names that start with a dot "." character ashidden. Supports GPT disks if the Windows version used also does. Supports use of the Windows mountvol utility to create or delete drive letters for Ext2 volumes (except on Windows NT 4.0). See also section"Can drive letters also be configured from scripts?". What features are *not* supported? Inodes that are larger than 128 bytes are not supported. Access rights are not maintained. All users can access all the directories and files of an Ext2 volume. If a new file or directory is created, it inherits all the permissions, the GID and the UID from the directory where it has been created. There is one exception to this rule: a file (but not a directory) the driver has created always has cleared "x" permissions, it inherits the "r" and the "w" permissions only. See also section"What limitations arise from not maintaining access rights?". The driver does not allow accessing special files at Ext2 volumes, the access will be always denied. (Special files are sockets, soft links, block devices, character devices and pipes.) Alternate 8.3-DOS names are not supported (just because there is no place to store them in an Ext2 file system). This can prevent legacy DOS applications, executed by the NTVDM of Windows, from accessing some files or directories. Currently the driver does not implement defragging support. So defragmentation applications will neither show fragmentation information nor defragment any Ext2 volume. This software does not achieve booting a Windows operating system from an Ext2 volume. LVM volumes are not supported, so it is not possible to access them.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

波哥的技术积累

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值