dojo.store/Cache/Observable/Memory

 dojo.store.Cache

restStore = new dojo.store.JsonRest(...); memoryStore = new dojo.store.Memory(); store = new dojo.store.Cache(restStore, memoryStore); store.get(1) -> Returns the object with an id of 1 by making a GET request store.get(1) -> Returns the object, using the local memory cache store.put({id:2, name:"two"}) -> Stores the object in both master and cache store store

 dojo.store.Observable

// create the initial Observable store store = dojo.store.Observable(new dojo.store.Memory({data: someData})); // query the store var results = store.query({rating:5}); // do something with the initial result set results.forEach(insertRow); // now listen for any changes var observeHandle = results.observe(function(object, removedFrom, insertedInto){   if(removedFrom > -1){ // existing object removed     removeRow(removedFrom);   }   if(insertedInto > -1){ // new or updated object inserted     insertRow(insertedInto, object);   } }); // this will trigger an addition to the result set (the observe listener will be called) store.put({rating: 5, id: 3}); // this will *not* trigger a observe event, since the object does not match the query constraint (query was for rating = 5) store.put({rating: 3, id: 4}); // if this object was in the result set, it will trigger a observe event store.remove(2); // done observing, any further modifications will not trigger our listener observeHandle.cancel();

 dojo.store.Memory

var someData = [   {id:1, name:"One"},   {id:2, name:"Two"} ]; store = new dojo.store.Memory({data: someData}); store.get(1) -> Returns the object with an id of 1 store.query({name:"One"}) -> // Returns query results from the array that match the given query store.query(function(object){   return object.id > 1; }) -> // Pass a function to do more complex querying store.put({id:3, name:"Three"}); // store the object with the given identity store.remove(3); // delete the object

转载于:https://my.oschina.net/bigyuan/blog/58029

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值