扩展Ext的JsonReader

本文介绍如何使用ExtJS框架中的JsonReader组件读取JSON数据,并通过Store组件进行数据管理和展示。具体包括自定义JsonReader类以适应特定的数据格式,以及在加载数据前后的事件监听处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var MyJsonReader = Ext.extend(Ext.data.JsonReader, {
	read: function(response){
        var json = response.responseText;
        var o = Ext.decode(json);
        if(!o)
        {
            throw {message: 'JsonReader.read: Json object not found'};
        }
        
        this.responseJsonObject = o;
        return this.readRecords(o);
    }
});

var myReader = new MyJsonReader(
	{totalProperty: "totalCount", root: "root"},
	[
	 	{name: "priceId"},
	 	{name: "areaCode"},
	 	{name: "deptCode"},
	 	{name: "deptName"},
	 	{name: "priceTypeCode"},
	 	{name: "priceBallotQty"},
	 	{name: "priceWeightQty"},
	 	{name: "createdEmpCode"},
	 	{name: "createdTm"},
	 	{name: "modifiedEmpCode"},
	 	{name: "modifiedTm"}
	]
);

var store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({url:"queryPriceByPage.action"}),
		reader: myReader,
		listeners: {
			beforeLoad: function(){
				if(Ext.isEmpty(Ext.getCmp("areaCodeCombox").getValue(), false))
				{
					Ext.Msg.alert("提示", "请选择地区代码!");
					return false;
				}
				
				this.baseParams = queryFormPanel.getForm().getValues();
	  			this.baseParams['limit'] = gridPanel.getTopToolbar().pageSize;
			},
			load: function(){
				Ext.getCmp("deptCountLabel").setText("  网点总数:" 
						+ myReader.responseJsonObject.allDeptCount 
						+ "         已配置数:"
						+ myReader.responseJsonObject.configDeptCount
						+ "         未配置数:"
						+ "<font style='font-weight:bold;color:red'>" + myReader.responseJsonObject.notConfigDeptCount, false) + "</font>";
			}
		}
	});

JsonRPC 2.0 Client and Server ============================= 轻量级 Json-RPC 2.0 客户端和服务端的php扩展,基于 multi_curl epoll的并发客户端,依据[jsonrpc](http://www.jsonrpc.org/)协议规范。 服务端: $server = new Jsonrpc_Server(); // style one function variable $add1 = function($a, $b){     return $a   $b; }; $server->register('addition1', $add1); // style two function string function add2($a, $b){   return $a   $b; } $server->register('addition2', 'add2'); // style three function closure $server->register('addition3', function ($a, $b) {     return $a   $b; }); //style four class method string class A  {   static public function add($a, $b)   {     return $a   $b;   } } $server->register('addition4', 'A::add'); echo $server->execute(); //output >>> //{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}} 客户端: $client = new Jsonrpc_Client(1); $client->call('http://localhost/server.php', 'addition1', array(3,5)); $client->call('http://localhost/server.php', 'addition2', array(10,20)); $client->call('http://localhost/server.php', 'addition3', array(2,8)); $client->call('http://localhost/server.php', 'addition4', array(6,15)); /* ... */ $result = $client->execute(); var_dump($result); //output >>> /* array(2) {   [0]=>   array(3) {     ["jsonrpc"]=>     string(3) "2.0"     ["id"]=>     int(110507766)     ["result"]=>     int(8)   }   [1]=>   array(3) {     ["jsonrpc"]=>     string(3) "2.0"     ["id"]=>     int(1559316299)     ["result"]=>     int(30)   }   ... } */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值