首页 > 代码库 > extjs 省市县 读取

extjs 省市县 读取

    var provinceCode = '';    var cityCode = '';    var areaCode = '';//编辑显示
	var editStore = new Ext.data.Store({
 		proxy : new Ext.data.HttpProxy({
			url : getContextPath()+'/grid!toEdit.asp?vo.major=10201'//TODO
		}),
		reader : new Ext.data.JsonReader({
			root : 'data',
			totalProperty : 'totalCount',
			idProperty : 'id'
		}, [ 
			{name : 'id',mapping : 'id'},
			{name : 'name',mapping : 'name'},
			{name : 'sex',mapping : 'sex'},
			{name : 'nation',mapping : 'nation'},
			{name : 'college',mapping : 'college'},
			{name : 'major',mapping : 'major'},
			{name : 'grade',mapping : 'grade'},
			{name : 'classs',mapping : 'classs'},
			{name : 'idcard',mapping : 'idcard'},
			{name : 'birth',mapping : 'birth'},
			{name : 'politicalstatus',mapping : 'politicalstatus'},
			{name : 'phone',mapping : 'phone'},
			{name : 'originnum',mapping : 'originnum'},
			{name : 'detailAddress',mapping : 'detailAddress'},
			{name : 'municipiosnum',mapping : 'municipiosnum'},
			{name : 'homephone',mapping : 'homephone'},
			{name : 'schoolstatus',mapping : 'schoolstatus'},
			{name : 'medicalinsurance',mapping : 'medicalinsurance'},
		    {name : 'commerciaLinsurance',mapping : 'commerciaLinsurance'},
		    {name : 'originLoan',mapping : 'originLoan'},
			{name : 'countryLoan',mapping : 'countryLoan'},
			{name : 'poorStudent',mapping : 'poorStudent'},
			{name : 'dormitorybuild',mapping : 'dormitorybuild'},
			{name : 'dormitorynum',mapping : 'dormitorynum'},
			{name : 'province',mapping : 'province'},
			{name : 'city',mapping : 'city'},
			{name : 'area',mapping : 'area'}
		])
	});
//省
	var addprovinceStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : getContextPath()+"/area!province.asp"
		}),
		reader : new Ext.data.JsonReader({
			root : 'data',
			id : 'provinceId'
		},[ {
			name : 'provinceId',
			mapping : 'provinceId'
		}, {
			name : 'provinceCode',
			mapping : 'provinceCode'
		}, {
			name : 'provinceName',
			mapping : 'provinceName'
		}]),listeners: {  
      	load: function() {
           addprovinceCombobox.setValue(provinceCode );  <pre name="code" class="javascript">           provinceCode=''; 
      }  
}
	});
	addprovinceStore.load();
	var addprovinceCombobox = new Ext.form.ComboBox({
		id:'addprovince',
		width:122,
        fieldLabel:'省',  
        name:'province',
        hiddenName:'province',
        mode:'local',
        editable: false,
       	valueField: 'provinceCode',
        displayField: 'provinceName',
        triggerAction:'all',
        store: addprovinceStore,
		listeners : {
			'select' : function(combo, record, index) {
				addcityStore.proxy = new Ext.data.HttpProxy({
					url : getContextPath()+'/area!city.asp?vo.provinceCode=' + combo.value
				});
				addcityCombobox.clearValue();
				addcityStore.load();
			}
		}
	});
	//市
	var addcityStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : getContextPath()+"/area!city.asp"
		}),
		reader : new Ext.data.JsonReader({
			root : 'data',
			id : 'cityId'
		},[ {
			name : 'cityId',
			mapping : 'cityId'
		}, {
			name : 'cityName',
			mapping : 'cityName'
		}, {
			name : 'cityCode',
			mapping : 'cityCode'
		}]),listeners: {  
      	load: function() {
           addcityCombobox.setValue(cityCode);  
           cityCode='';
     	 }  
      }
	});
	var addcityCombobox = new Ext.form.ComboBox({
		id:'addcity',
		width:122,
        fieldLabel:'市',  
        name:'city',
        hiddenName:'city',
        mode:'local',
        editable: false,
       	valueField: 'cityCode',
        displayField: 'cityName',
        triggerAction:'all',
        store: addcityStore,
		listeners : {
			'select' : function(combo, record, index) {
				addareaStore.proxy = new Ext.data.HttpProxy({
					url : getContextPath()+'/area!area.asp?vo.cityCode=' + combo.value
				});
				addareaCombobox.clearValue();
				addareaStore.load();
			}
		}
	});
	//县
	var addareaStore = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : getContextPath()+"/area!area.asp"
		}),
		reader : new Ext.data.JsonReader({
			root : 'data',
			id : 'areaId'
		},[ {
			name : 'areaId',
			mapping : 'areaId'
		}, {
			name : 'areaCode',
			mapping : 'areaCode'
		}, {
			name : 'areaName',
			mapping : 'areaName'
		}]),listeners: {  
      	load: function() {
           addareaCombobox.setValue(areaCode);  
           areaCode='';
     	 }  
      }
	});
	var addareaCombobox = new Ext.form.ComboBox({
		id:'addarea',
		width:122,
        fieldLabel:'县',  
        name:'area',
        hiddenName:'area',
        mode:'local',
        editable: false,
       	valueField: 'areaCode',
        displayField: 'areaName',
        triggerAction:'all',
        store: addareaStore
	});
	
editStore.load({
					params: {
						id: gridPanel.getSelectionModel().getSelected().data.id
					},
					callback: function(records, options, success){
						if(success){
							addForm.getForm().loadRecord(editStore.getAt(0));
							
							//TODO
							var num = editStore.getAt(0).data.municipiosnum;                                                        provinceCode = num.substring(0,2)+'0000';                                                        cityCode = num.substring(0,4)+'00';
							areaCode = num;
							addcityStore.proxy = new Ext.data.HttpProxy({
								url : getContextPath()+'/area!city.asp?vo.provinceCode=' + num.substring(0,2)+'0000'
							});
							addcityCombobox.clearValue();
							addcityStore.load();
							
							addareaStore.proxy = new Ext.data.HttpProxy({
								url : getContextPath()+'/area!area.asp?vo.cityCode=' + num.substring(0,4)+'00'
							});
							addareaCombobox.clearValue();
							addareaStore.load();
							
							}else{
							showErrorMsg("加载学生信息失败,请刷新数据后重试",gridPanel);
						}
					}
				});
			addWin.setTitle("修改学生");
			addWin.show();
			addForm.getForm().enableAll();
			addForm.getForm().findField('addid').disable();			
		}


extjs 省市县 读取