Ext扩展:JsonRpcSotre

刚刚弄完JsonRpc.由于Ext的数据是基于Store的,马不停蹄,构造自己的JsonRpcStore,同时发现了以前写的RpcStore在IE上有很多问题,经过修改代码如下:

Ext.ux.JsonRpcProxy = function(c) {
	Ext.ux.JsonRpcProxy.superclass.constructor.call(this);
	this.url = c.url;
};
Ext.extend(Ext.ux.JsonRpcProxy, Ext.data.DataProxy, {
	load : function(params, reader, callback, scope, arg) {
		if (this.fireEvent("beforeload", this, params) !== false) {
			var o = {
				params : params,
				request : {
					callback : callback,
					scope : scope,
					arg : arg
				},
				reader : reader,
				callback : this.loadResponse,
				scope : this
			};
			JsonRpc.request(this.url, [o.params], function(r, e) {
				o.callback.call(o.scope, o, r && !e, r || e);
			});
		} else {
			callback.call(scope || this, null, arg, false);
		}
	},
	loadResponse : function(o, success, response) {
		if (!success) {
			this.fireEvent("loadexception", this, o, response);
			o.request.callback
					.call(o.request.scope, null, o.request.arg, false);
			return;
		}
		var result;
		try {
			result = o.reader.readRecords(response);
		} catch (e) {
			this.fireEvent("loadexception", this, o, response, e);
			o.request.callback
					.call(o.request.scope, null, o.request.arg, false);
			return;
		}
		this.fireEvent("load", this, o, o.request.arg);
		o.request.callback.call(o.request.scope, result, o.request.arg, true);
	},
	update : function(dataSet) {
	},
	updateResponse : function(dataSet) {
	}
});

Ext.ux.JsonRpcStore = function(c) {
	Ext.ux.JsonRpcStore.superclass.constructor.call(this, Ext.apply(c, {
		proxy : new Ext.ux.JsonRpcProxy({
			url : c.url
		}),
		reader : new Ext.data.JsonReader(c, c.fields)
	}));
}
Ext.extend(Ext.ux.JsonRpcStore, Ext.data.Store);
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值