EasyUi+Ajax实现二级联动

参考于 http://blog.csdn.net/lhq13400526230/article/details/12427225#comments

作为一名初学者,记录下自己学习过程中的心得与总结

源码: jsp部分

$(function() {   
    // 下拉框选择控件,下拉框的内容是动态查询数据库信息 
    $('#lanmu').combobox({ 
                url:'easyui!lanmu',   
                //不可编辑状态  
                cache: false,  
                panelHeight: 'auto',//自动高度适合  
                valueField:'classid',     
                textField:'classname', 
                value:"请选择栏目",  


                onHidePanel: function(){  
            $("#leibie").combobox("setValue",'请选择类别');  
            var lanmuid = $('#lanmu').combobox('getValue');       
              
            $.ajax({  
                type: "POST",  
                url: "/SSSH/easyui!leibie?classid="+lanmuid,  
                cache: false,  
                dataType : "json",  
                success: function(data){  
                $("#leibie").combobox("loadData",data);  
                        }  
                    });       
                }  
         });   


 $('#leibie').combobox({   
        //url:'itemManage!categorytbl',   
        editable:false, //不可编辑状态  
        cache: false,  
        panelHeight: 'auto',//自动高度适合  
        valueField:'id',     
        textField:'teacher'  
       });  
      
    });  


<body>
   <div id="tb" style="padding: 3px">  
      <form >  
  
            <span>所属栏目:</span>   
            <select  id="lanmu" class="lanmu" style="width:160px; border: 1px solid #ccc"> </select>  
            <span>类别:</span>   
            <select  id="leibie" class="leibie" style="width:160px; border: 1px solid #ccc"> </select>  
              
      </form>  
    </div>  
  </body>

 转换Json字符串需要用到

public String toJsonArray(List list) throws IOException{  
     HttpServletResponse response = ServletActionContext.getResponse();  
     HttpServletRequest request = ServletActionContext.getRequest();  
     JSONArray json = JSONArray.fromObject(list); 
     response.setCharacterEncoding("utf-8");// 指定为utf-8  
     response.getWriter().write(json.toString());// 转化为JSOn格式  
     return NONE;  
 }  

得到关联的两个实体类需要转换成VO类。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值