ExtJS--4.2クライアントエージェント(proxy)

3304 ワード

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>