需求是这个样的 获取当前登录人所在的城市 由城市下拉框默认出省来 再由城市获得车贷营业部部门
一般省市县有pid 这个数据库的问题这里就不提了。
直接上代码,先看jsp代码。
<tr height="30">
<td align="right"><font color="red">*</font>请选择所在城市:</td>
<td>
<!--<input class="easyui-combobox" editable="false" hasDownArrow="false" id="city" name="city" style="width:130px;" />
-->
<input id="currProvince" class="easyui-combobox"
name="presentAddressProvince"
style="width: 100px;" required="true"
value="">
</input>
<input id="city" class="easyui-combobox"
name="city"
style="width: 100px; height: 10px;" required="true"
value="">
</input>
</td>
<td align="right"><font color="red">*</font>车贷营业部:</td>
<td>
<input id="carDepartmentId" class="easyui-combobox" name="carDepartmentId" editable="false" data-options="required:true" style="width:147px;">
</input>
<input type="hidden" id="carDepartmentName" name="carDepartmentName"/>
</td>
</tr>
js代码
$(function(){
ajaxSubmit(
//通过初始化 加载 ajaxSubmit方法向后台请求
serverName
+ "/autoLoanConsultcontroller/getCityObjByCurrentLogin.do",
{
},//这里是参数列表
function(r) {
//初始化下拉框 easyui-combobox 注意这个是easeUI框架里面的 然后给每个下拉框附上onclick方法 可以看到返回的数据中r里面有省市信息,也了可能是 空的
cityComboboxStart("currProvince","city",r.parentId,r.cityCode,"carDepartmentId");
}
);
}
function cityComboboxStart(province,city,pid,cid,carDepartmentId){
//想后台调方法加载省和市的列表信息
ajaxSubmit(serverName+"/NSC/selectNSCDpartById.do",{pid:pid,cid:cid},function(resultMap)
{
if(resultMap != null && resultMap != "")
{
$("#" + province).combobox(
{
editable : false,
data : resultMap.pList,
textField : 'cityName',
valueField : 'cityCode',
mode : 'remote',
delay : 500,
width : '100',
value:pid,
validType:"selectValueCity['"+province+"','请选择']",
onSelect : function(value) {
$("#" + city).combobox("setValue","");
$("#" + carDepartmentId).combobox("setValue","");
$("#" + city).combobox({
editable : false,
url : serverName+ '/NSC/listCity.do?parentId='+ value.cityCode,
textField : 'cityName',
valueField : 'cityCode',
mode : 'remote',
delay : 500,
width : '100',
value:"1",
validType:"selectValueCity['"+city+"','请选择']",
onSelect : function(value) {
ajaxSubmit(
serverName
+ "/autoLoanConsultcontroller/selectDepartmentByParamCity.do?cityCode="+value.cityCode,
function(r) {
$("#carDepartmentId").combobox({
valueField : "officeCode",
textField : "officeName",
data:r,
value:"",
onSelect : function(value){
$("#carDepartmentName").val(value.officeName);
}
});
});
}
});
}
});
$("#" + city).combobox({
editable : false,
data : resultMap.cList,
textField : 'cityName',
valueField : 'cityCode',
mode : 'remote',
delay : 500,
width : '100',
value:cid,
validType:"selectValueCity['"+city+"','请选择']",
onSelect : function(value) {
ajaxSubmit(
serverName
+ "/autoLoanConsultcontroller/selectDepartmentByParamCity.do?cityCode="+value.cityCode,
function(r) {
$("#carDepartmentId").combobox({
valueField : "officeCode",
textField : "officeName",
data:r,
value:"",
onSelect : function(value){
$("#carDepartmentName").val(value.officeName);
}
});
});
}
});
$("#" + carDepartmentId).combobox(
{
editable : false,
data :resultMap.saleOfficeList,
valueField : "officeCode",
textField : "officeName",
mode : 'remote',
width : '100',
delay : 500,
value:"",
onSelect : function(value){
$("#carDepartmentName").val(value.officeName);
}
});
}
});
}
后台的方法不一一列出只给出一个关键的
@RequestMapping(value="selectNSCDpartById")
public @ResponseBody Map selectNSCDpartById(String pid,String cid){
NationalStandard nationalStandard = new NationalStandard();
nationalStandard.setCityCode(1);
nationalStandard.setCityName("请选择");
List pLists=nationalStandardService.selectNSC();
List<NationalStandard> pList=new ArrayList<NationalStandard>();
pList.add(nationalStandard);
pList.addAll(pLists);
String q="";
Map resultMap= new HashMap();
if(null!=pid&&pid!="")
{
List<NationalStandard> cList=this.showCity(q, Integer.parseInt(pid));
//cList.add(nationalStandard);
resultMap.put("cList", cList);
}
if(null!=cid&&cid!="")
{
List<SaleOffice> saleOfficeList = null;
try {
saleOfficeList = autoLoanService.queryCityMapping(cid);
} catch (Exception_Exception e) {
e.printStackTrace();
}
SaleOffice saleOffice = new SaleOffice();
saleOffice.setOfficeCode("");
saleOffice.setOfficeName("请选择");
saleOfficeList.add(0, saleOffice);
resultMap.put("saleOfficeList", saleOfficeList);
}
resultMap.put("pList", pList);
return resultMap;
}