jsp页面html:
<tr height="35"> <td style="color:#6699CC;">灾害类型id:</td> <td> <input id="d1" class="easyui-combobox" style='width:100px;height:25px' data-options="required:true,editable:false" /> <input id="d2" class="easyui-combobox" style='width:100px;height:25px' data-options="required:true,editable:false,valueField:'id',textField:'text'" /> <input name="distypeid" id="distypeid" class="easyui-combobox" style='width:100px;height:25px' data-options="required:true,editable:false,valueField:'id',textField:'text'" /> </td> </tr>
jsp页面js:
$(function(){ $('#d1').combobox({ url: 'getDsContrast.do', valueField: 'id', textField: 'text', onSelect:function(record){ $("#d2").combobox("setValue",''); //清空数据 $("#distypeid").combobox("setValue",''); var url = 'getDsContrast.do?code='+record.id; $('#d2').combobox('reload', url); } }); $('#d2').combobox({ onSelect:function(record){ $("#distypeid").combobox("setValue",''); var url = 'getDsContrast.do?code='+record.id; $('#distypeid').combobox('reload', url); } }); });
Controller:
@Log(message="自然灾害联动") @RequestMapping("getDsContrast") @ResponseBody public List<EUComboBox> getDsContrast(HttpServletRequest request, HttpServletResponse response) { String code = request.getParameter("code"); List<EUComboBox> comList = ep_disastersService.getDsContrast(code); return comList; }
Service:
/** 获取自然数据字典 */ public List<EUComboBox> getDsContrast(String code) { //创建条件实例 Ep_DisastertypeExample example = new Ep_DisastertypeExample(); //创建条件添加pid Ep_DisastertypeExample.Criteria criteria = example.createCriteria(); if(StringUtils.isBlank(code)){ criteria.andDistypepidIsNull(); }else { criteria.andDistypepidEqualTo(code); } List<Ep_Disastertype> list = ep_disastertypeMapper.selectByExample(example); //定义ComboBox对象 List<EUComboBox> comList=new ArrayList<EUComboBox>(); for(Ep_Disastertype ed : list){ EUComboBox com = new EUComboBox(); com.setId(ed.getDistypeid()); com.setText(ed.getDistypename()); comList.add(com); } return comList; }
EUComboBox:
public class EUComboBox { public EUComboBox(){ } public EUComboBox(String id,String text){ this.id=id; this.text=text; } //value值 private String id; //显示文本 private String text; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getText() { return text; } public void setText(String text) { this.text = text; } }