使用dojo.store.Memory

本文通过一个小程序说明dojo.store.Memory的用法

<!DOCTYPE html>
<html >
<head>
<script type="text/javascript" src="./dojo172/dojo/dojo.js"	djConfig="parseOnLoad:true"></script>
<link rel="stylesheet" href="./dojo172/dijit/themes/claro/claro.css">
<script>
	dojo.require("dojo.store.Memory");
	var someData = [{id:1, title:"One"}];
	var json1 = {"id":"5","title":"封面","author":"王硕"};
	store = new dojo.store.Memory({data: someData});//初始化store对象,传空参数也行	
	var b = store.put(json1);
	console.log(b);//输出5
	json2 = {"id":"1","title":"封面","author":"王硕"};//标签可以带也可不带引号,值一样
	store.put(json2);//覆盖id值为1的对象。
	var d = store.get(1)// -> 返回id为1的对象,这里返回json2对应的对象
	var n = store.query({title:"One"});// -> // 返回符合条件的对象集合,这里返回id为1和5的对象
	var a = store.query(function(object){ //返回id值大于1的对象
	     return object.id > 1;
	})// 传递函数能完成更复杂的查询
	store.put({id:3, name:"Three"}); // store the object with the given identity
	store.remove(3); // delete the object
</script>
</head>
<body class="claro">   
</body>
</html>

  

posted @ 2012-08-17 17:29  gmartincn  阅读(1002)  评论(0编辑  收藏  举报