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);
 

你可能感兴趣的:(C++,c,ext,IE,C#)