您的位置:首页 > 其它

关于ext.data部分

2008-11-26 10:36 141 查看
转自:http://www.javaeye.com/post/437044

Ext控件如何取得数据?

首先我需要知道如何取到数据,于是定义

Ext.data.HttpProxy 其中的URL属性或者指向1个本地文件,或者是发送一个网络请求

OK中途传输一切顺利,于是我得到一个数据的集合,我如何从这个集合中把数据取出来,按照

我定义的格式来安排数据,接下来定义

Ext.data.JsonReader(如果取到的数据是JSON格式的字符串),或者其他,假设是JSON字串

API文档里有段定义

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

一切顺利,现在我能够让Ext认识服务器返回的JSON字串,那么我现在需要的是一个格式化后的cache,把

读到的字串一项项的放入其中,这样控件可以从这个cache里读取数据并且显示,注意jsonreader第2项参数

Employee这个API有定义

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.

]);

上面的代码做了什么?定义了格式化的cache,于是一项项的数据通过jsonreader,按record的格式放入

其中,注意mapping定义了原始数据和格式化后数据的影射关系,好了把上面的数据请求,读取方法和放数据的

cache包装在一起就成了Ext.data.Store定义的东西.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: