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代码中:

省:&nbsp;&nbsp;<s:textfield name="secondaryProvince" id="secondaryProvince" size="30"/><br>
市:&nbsp;&nbsp;<s:textfield name="secondaryCity" id="secondaryCity" size="30"/><br>
区县:&nbsp;<s:textfield name="secondaryCounty" id="secondaryCounty" size="30"/>


Java代码中:

/**
* 自动查找数据字典(省)
*/
public void searchPro(){
try {
List<CodeType> proList = new ArrayList<CodeType>();
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<CodeType> cityList = new ArrayList<CodeType>();
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<CodeType> countryList = new ArrayList<CodeType>();
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();
}
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值