Ext之JsonStore读取本地json文件

-

//用于选择的Grid

var fields =  [
	           {name: 'name'},
	           {name: 'type'},
	           {name: 'length'},
	           {name: 'width'},
	           {name: 'weight'}
	        ];  
	 
	    var selectStore = new Ext.data.JsonStore({  
		    url: 'data/defaultColumnNames.json',  
		    root: 'rows',  
		    autoLoad: true,  
		    fields: fields
	    }); 
	    
	    var selectCm = new Ext.grid.ColumnModel({
	    		defaults: {
			        menuDisabled: true
			    },
		        columns: [{
		        	id: 'name',
		            header: '可选字段',
		            dataIndex: 'name',
		            align:'center'
		        }]
		    });
		    
	    var selectGrid = new Ext.grid.GridPanel({
					store : selectStore,
					cm : selectCm,
					ddGroup : 'secondGridDDGroup',
					height:300,
					width:120,
					enableDragDrop : true,
					frame: true,
					border:true,
					stripeRows : true
				});   





====================================================
方法二:

 //定义数据源
    var store = new Ext.data.JsonStore({
    	root:'root',
    	url:'data/rentFeeTemplate.json',    	
        fields: [
        	'name',//模板名称
        	'rent',//租金
        	'size',//面积
        	'rebate'//折扣
        ]
    });
    
    store.load();




对应的json文件:data/rentFeeTemplate.json

{
	'root':[{
		name:'教授住房',
		rent:2000,
		size:30,
		rebate:	0.1
	},{
		name:'副教授住房',
		rent:2000,
		size:30,
		rebate:	0.1
	},{
		name:'专家住房',
		rent:2000,
		size:30,
		rebate:	0.1
	},{
		name:'学生住房',
		rent:2000,
		size:30,
		rebate:	0.1
	},{
		name:'普通住房',
		rent:2000,
		size:30,
		rebate:	0.1
	}]

}














--

































-

你可能感兴趣的:(数据,ext,本地,读取,jsonstore)