EasyUI实现多级联动

选了省之后,会自动跳到选择市,市选择完了会自动跳到所属市的区县,完成这个就要用到easyUI提供的组件来实现了。

JS中:

//自动搜索 
$('#secondaryProvince').combogrid({
delay:500,
panelWidth:200,
idField:'name',      //真实要传的值
textField:'name',   //显示的值
mode:'remote',
url:'codeTypeAction_searchPro.action',   //远程地址
columns:[[
{field:'name',title:'省份名称',width:100},
{field:'pinCode',title:'拼音码',width:100}
]],
onSelect:function(){
var secondaryProvince = $('#secondaryProvince').combogrid('getValue');
$('#secondaryCity').combobox('setValue' , '');
   $("#room input.validatebox-text").focus();
$('#secondaryCity').combobox('reload' , 'codeTypeAction_searchCity.action?parentId='+secondaryProvince);
$('#secondaryCity').combobox('showPanel');
  
}
});

$('#secondaryCity').combobox({
delay:500,
panelWidth:150,
mode:'remote',
valueField:'name',
textField:'name',
url:'codeTypeAction_searchCity.action',
onSelect:function(){
var secondaryCity = $('#secondaryCity').combobox('getValue');
//$('#secondaryCity').val(secondaryCity);
//$('#rfPerson').combogrid('reload' , 'ReportFaultAction!searchStaff.do?unitId='+unitId);
$.ajax({
  type:"post",
      url:'codeTypeAction_searchCountry.action',
      secureuri:true,// 安全提交,默认为false
      data:{
      'parentId':secondaryCity,
      'typeId':1
      },
      dataType:'json',
      success:function(data){
       $('#secondaryCounty').combogrid('setValue' , '');
   //$('#rfPerson').combogrid('enable');
   $("#people input.validatebox-text").focus();
$('#secondaryCounty').combogrid('showPanel');
       $('#secondaryCounty').combogrid('grid').datagrid('loadData',data);
 }
});

}
});

$('#secondaryCounty').combogrid({
delay:500,
panelWidth:200,
idField:'name',
textField:'name',
mode:'remote',
url:'codeTypeAction_searchCountry.action',
columns:[[
{field:'name',title:'区县名称',width:100},
{field:'pinCode',title:'拼音码',width:100}
]]
});

Html代码中:

省:  

市:  

区县: 


Java代码中:

/**
* 自动查找数据字典(省)
*/
public void searchPro(){
try {
List proList = new ArrayList();
String q = getRequest().getParameter("q")== null?"":getRequest().getParameter("q");
if(!"".equals(q.trim())){
// 查询符合条件的数据与数据总数
if(q.matches("^[A-Za-z]+$")){
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
       .addWhereCondition("c.type = ?",3) // 数据字典类型
       .addWhereCondition("c.status = ?","1") // 数据字典状态
       .addWhereCondition("c.pinCode like ?","%"+q.trim().toLowerCase()+"%") // 数据字典拼音码
       .addOrderByProperty("c.serialNumber", true); // 按序列号排序
proList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}else{
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
       .addWhereCondition("c.type = ?",3) // 数据字典类型
       .addWhereCondition("c.status = ?","1") // 数据字典状态
       .addWhereCondition("c.name like ?","%"+q.trim()+"%") //  数据字典拼音码
       .addOrderByProperty("c.serialNumber", true); // 按序列号排序
proList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}
}else{
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
       .addWhereCondition("c.type = ?",3) // 数据字典类型
       .addWhereCondition("c.status = ?","1") // 数据字典状态
       .addOrderByProperty("c.serialNumber", true); // 按序列号排序
proList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}

String text = JSON.toJSONString(proList);
// 如果不存在typeId 说明是第一次访问此方法 执行页面返回 否则打印出json格式字符串
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().println(text);
} catch (Exception ex) {
ex.printStackTrace();
try {
getResponse().setStatus(555);
getResponse().getWriter().println("查询失败");
} catch (IOException e) {
e.printStackTrace();
}
}
}

/**
* 自动查找数据字典(市)
*/
public void searchCity(){
try {
List cityList = new ArrayList();
if(parentId != null && parentId.length() != 0){
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",4) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.parent.name = ?",parentId) // 数据字典上一级
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

cityList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);

}else {
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",4) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

cityList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}


String text = JSON.toJSONString(cityList);
// 如果不存在typeId 说明是第一次访问此方法 执行页面返回 否则打印出json格式字符串
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().println(text);
} catch (Exception ex) {
ex.printStackTrace();
try {
getResponse().setStatus(555);
getResponse().getWriter().println("查询失败");
} catch (IOException e) {
e.printStackTrace();
}
}
}

/**
* 自动查找数据字典(区县)
*/
public void searchCountry(){
try {
List countryList = new ArrayList();
String q = getRequest().getParameter("q")== null?"":getRequest().getParameter("q");
if(!"".equals(q.trim())){
// 查询符合条件的数据与数据总数
if(q.matches("^[A-Za-z]+$")){
if(parentId != null && parentId.length() != 0){
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.pinCode like ?","%"+q.trim().toLowerCase()+"%") // 数据字典拼音码
.addWhereCondition("c.parent.name = ?",parentId) // 数据字典上一级
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);

}else {
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.pinCode like ?","%"+q.trim().toLowerCase()+"%") // 数据字典拼音码
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}
}else{
if(parentId != null && parentId.length() != 0){
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.name like ?","%"+q.trim()+"%") // 数据字典拼音码
.addWhereCondition("c.parent.name = ?",parentId) // 数据字典上一级
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);

}else {
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.name like ?","%"+q.trim()+"%") // 数据字典拼音码
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}
}
}else{
if(parentId != null && parentId.length() != 0){
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addWhereCondition("c.parent.name = ?",parentId) // 数据字典上一级
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);

}else {
HqlHelper hqlHelper = new HqlHelper(CodeType.class, "c")//
.addWhereCondition("c.type = ?",5) // 数据字典类型
.addWhereCondition("c.status = ?","1") // 数据字典状态
.addOrderByProperty("c.serialNumber", true); // 按序列号排序

countryList = codeTypeService.queryWithSplitPage(hqlHelper,null,null);
}
}

String text = JSON.toJSONString(countryList);
// 如果不存在typeId 说明是第一次访问此方法 执行页面返回 否则打印出json格式字符串
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().println(text);
} catch (Exception ex) {
ex.printStackTrace();
try {
getResponse().setStatus(555);
getResponse().getWriter().println("查询失败");
} catch (IOException e) {
e.printStackTrace();
}
}
}

你可能感兴趣的:(Jquery-EasyUi)