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

ExtJS--4.2服务端代理(proxy)

Ajax方式代理:

	<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 : "ajax",
				url : "jsp/getJson.jsp",
				reader : {type : "json"}
			}
		});
		
		//遍历Store
		Ext.onReady(function(){
			var msg = [];
			personStore.load({
				callback: function (records, operation, success) {
					if(success){
						Ext.Array.each(records,function(person){
							msg.push(person.get("name")+" , "+person.get("age"));
						});
						Ext.Msg.alert("提示",msg.join("<br/>"));
					}
				}
			});
		});
	</script>

?