日期:2014-05-16  浏览次数:20498 次

ExtJS--4.2客户端代理(proxy)

memory代理方式:

<script type="text/javascript">
		//定义数据模型
		Ext.define("Person",{
			extend : "Ext.data.Model",
			fields : [
				{name:"name", type:"string"},
				{name:"age", type:"int"}
			]
		});
		
		//定义Store
		var personStore = Ext.create("Ext.data.Store",{
			model : "Person",
			proxy : {
				type : "memory"
			}
		});
		
		//往Store添加元素
		personStore.add({name:"Ivan",age:"27"});
		personStore.add({name:"study",age:"1"});
		
		//遍历Store
		var msg = [];
		personStore.each(function(person){
			msg.push(person.get("name")+" , "+person.get("age"));
		});
		Ext.onReady(function(){
			Ext.Msg.alert("提示",msg.join("<br/>"));
		});
	</script>

?

LocalStorage代理方式:

	<script type="text/javascript">
		//定义数据模型
		Ext.define("Person",{
			extend : "Ext.data.Model",
			fields : [
				{name:"name", type:"string"},
				{name:"age", type:"int"}
			]
		});
		
		//定义Store
		var personStore = Ext.create("Ext.data.Store",{
			model : "Person",
			proxy : {
				type : "localstorage",
		        id  : "twitter-Searches"//必需加,否则提示不只一个LocalStorage
			}
		});
		
		//往Store添加元素
		personStore.add({name:"Ivan",age:"27"});
		personStore.add({name:"study",age:"1"});
		personStore.sync();
		
		//遍历Store
		var msg = [];
		personStore.load();
		personStore.each(function(person){
			msg.push(person.get("name")+" , "+person.get("age"));
		});
		Ext.onReady(function(){
			Ext.Msg.alert("提示",msg.join("<br/>"));
		});
	</script>

?

SessionStorage代理方式:

<script type="text/javascript">
		//定义数据模型
		Ext.define("Person",{
			extend : "Ext.data.Model",
			fields : [
				{name:"name", type:"string"},
				{name:"age", type:"int"}
			]
		});
		
		//定义Store
		var personStore = Ext.create("Ext.data.Store",{
			model : "Person",
			proxy : {
				type : "sessionstorage",
		        id : "myProxyKey"
			}
		});
		
		//往Store添加元素
		personStore.add({name:"Ivan",age:"27"});
		personStore.add({name:"study",age:"1"});
		personStore.sync();
		
		//遍历Store
		var msg = [];
		personStore.load();
		personStore.each(function(person){
			msg.push(person.get("name")+" , "+person.get("age"));
		});
		Ext.onReady(function(){
			Ext.Msg.alert("提示",msg.join("<br/>"));
		});
	</script>

?