Extjs学习笔记——Ext.data.JsonStore使用说明

Ext.data.JsonStore继承于Ext.data.Store。使得从远程JSON数据创建stores更为方便的简单辅助类。

JsonStore合成了Ext.data.HttpProxy与Ext.data.JsonReader两者。假设你须要其它类型的proxy或reader组合,那么你要创建以Ext.data.Store为基类的配置。


代码实例:

var store = new Ext.data.JsonStore({
    id:'id',
    url: 'get-images.php',
    root: 'images',
    totalProperty: 'rowCount',
    fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
});

他的返回值将形成例如以下的对象:


{
    images: [
        {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
        {name: 'Image Two', url:'/GetImage.php?

id=2', size:43.2, lastmod: new Date(2007, 10, 30)} ] }

以下我们依次说明下几个參数的含义:
id(String):用来唯一标识
url(String):假设有值传入,会为该URL创建一个HttpProxy对象
root(String):JSON对象的key指定,这里指的是server传递过来的json变量的命名
totalProperty:这里指的是查询出来的条数,也是由server传递过来
fields(Object[]):对象数组集合
在实际应用中fields我们能够使用遍历list等方式往里面传值。

posted on 2017-07-29 20:06  yjbjingcha  阅读(462)  评论(0编辑  收藏  举报

导航