当前位置: 代码迷 >> JavaScript >> JsonReader ArrayReader解析器的施用
  详细解决方案

JsonReader ArrayReader解析器的施用

热度:295   发布时间:2012-10-26 10:30:59.0
JsonReader ArrayReader解析器的应用
Ext.onReady(function(){

	var fields=["id","name","email","sex","age"];// 字段的描述,指列
	
	
	
	
	var data=[["1","lang","lijun@126.com","0","20"],
	["2","lang","lijun@126.com","0","20"],
	["3","lang","lijun@126.com","0","20"],
	["4","lang","lijun@126.com","0","20"],
	["5","lang","lijun@126.com","0","20"]];// 行,与field一一匹配,本地数据取值方式
	
	// store表示数据存储器
	var store=new Ext.data.Store({
	
		//数据存储器的数据
		data:data,//data必须为数组,才能够实用arrayReader
		//参数id表示唯一标识,采用ArrayReader数组解析器解析
		reader:new Ext.data.ArrayReader({id:"id"},fields)
	})
	
	
	var cm=new Ext.grid.ColumnModel([{
	header:"id",// 列名
	dataIndex:"id"  // 与fields一一对应
	},{
	header:"姓名",
	dataIndex:"name"  // 与fields一一对应
	},{
	header:"Email",
	dataIndex:"email"  // 与fields一一对应
	},{
	header:"性别",
	dataIndex:"sex"  // 与fields一一对应
	},{
	header:"年龄",
	dataIndex:"age"  // 与fields一一对应
	}]);
	
	var grid=new Ext.grid.GridPanel({
	
		title:'gridpanel',
	
		cm:cm,
		store:store,
		autoHeight:true
	})
	
	grid.render(Ext.getBody());
	
})

?

?

?

Ext.onReady(function() {

			var fields = ["id", "name", "email", "sex", "age"];// 字段的描述,指列

//			var data = [["1", "lang", "lijun@126.com", "0", "20"],
//					["2", "lang", "lijun@126.com", "0", "20"],
//					["3", "lang", "lijun@126.com", "0", "20"],
//					["4", "lang", "lijun@126.com", "0", "20"],
//					["5", "lang", "lijun@126.com", "0", "20"]];// 行,与field一一匹配,本地数据取值方式

			var jsondata = {total:10,result:[{//total标识表示总记录数,result表示对象属性
						id : "1",
						name : "lang1",
						email : "lijun@126.com",
						sex : "0",
						age : "20"
					}, {
						id : "2",
						name : "lang1",
						email : "lijun@126.com",
						sex : "0",
						age : "20"
					}, {
						id : "3",
						name : "lang1",
						email : "lijun@126.com",
						sex : "0",
						age : "20"
					}, {
						id : "4",
						name : "lang1",
						email : "lijun@126.com",
						sex : "0",
						age : "20"
					}, {
						id : "5",
						name : "lang1",
						email : "lijun@126.com",
						sex : "0",
						age : "20"
					}]}

			// store表示数据存储器
			var store = new Ext.data.Store({

						// 数据存储器的数据
						data : jsondata,// jsondata必须为json格式的数据
						// 参数id表示唯一标识,采用JsonReader解析Json格式的数据
						reader : new Ext.data.JsonReader({id:"id",root:"result",totalProperty:"total"},fields)
					})

			var cm = new Ext.grid.ColumnModel([{
						header : "id",// 列名
						dataIndex : "id" // 与fields一一对应
					}, {
						header : "姓名",
						dataIndex : "name" // 与fields一一对应
					}, {
						header : "Email",
						dataIndex : "email" // 与fields一一对应
					}, {
						header : "性别",
						dataIndex : "sex" // 与fields一一对应
					}, {
						header : "年龄",
						dataIndex : "age" // 与fields一一对应
					}]);

			var grid = new Ext.grid.GridPanel({

						title : 'gridpanel',

						cm : cm,
						store : store,
						autoHeight : true
					})

			grid.render(Ext.getBody());

		})

?

?