SSM+jquery多級聯動


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;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM