dojo store

dojo/store作为dojo数据存储模块,它具有简单,易用,快速存取和管理数据的能力。dojo/store是1.6版本后dojo基于HTML5的 IndexedDB object store API重新实现的模块,与之前版本旧的dojo/data中的存储是不同的。

详细的API这里就不讲述了,这些内容大家可以参考下面的网址
http://dojotoolkit.org/reference-guide/1.9/dojo/store.html

dojo/store所包含的几个重要模块

dojo/store/Memory 客户端对象存储,它是dojo/store中最基本的存储,你可以构建你的客户端存储,对其增删改查。
dojo/store/JsonRest 服务器端的对象存储 (用于REST/JSON) ,用它来管理服务器端的Ajax请求或者REST服务。
dojo/store/DataStore 适配器, 旧存储转换过成新存储,就可以使用新存储的API。
例如
require(["dojo/data/ItemFileWriteStore", "dojo/store/DataStore"], function(ItemFileWriteStore, DataStore){
    datastore = new ItemFileWriteStore({url:"data.json"});

    store = new DataStore({store: datastore});

    store.query("foo=bar").then(function(results){
        // use the query results returned from the server
    });
});
dojo/data/ObjectStore 适配器, 新存储转换成旧存储。
例如使用DataGrid时, DataGrid使用的是旧的存储,所以需要转换一下。
var objectStore = new dojo.store.JsonRest({target:"/Table/"});

var dataStore = new dojo.data.ObjectStore({objectStore: objectStore});

// we can now use dataStore with any legacy Dojo Data consumer
var grid = new dojox.data.DataGrid({
  store: dataStore,
  ...
});
dojo/store/Observable 用于对存储的变化进行监控的模块。
dojo/store/Cache 为存储增加缓存。
例如JsonRest作为主存储,Memory作为Cache
restStore = new JsonRest(...);
memoryStore = new Memory();
store = new Cache(restStore, memoryStore);

store.get(1) //通过请求去拿id为1的对象
store.get(1) //使用的是本地的Memory Cache
store.put({id:2, name:"two"}) //将对象保存在主存储和本地的Memory Cache
store.get(2) //使用本地的Memory Cache

存储作为dojo数据管理的基础是非常重要的,像Tree,Grid, Chart等组件都用它来做数据源。


本文转载自网易星期五的博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值