easyui url php一个类的方法,easyui的下拉框动态级联加载的实现方法(附代码)

本文详细介绍了如何使用EasyUI实现下拉框的动态级联加载,以高校学院和课程选择为例。首先展示了界面效果,接着提供了HTML和JS代码,展示如何根据学院选择动态加载课程。在后台,通过接口获取学院和课程数据并转化为JSON返回给前端。文章还强调了在实现过程中需要注意清除课程选项和正确传递参数等问题。
摘要由CSDN通过智能技术生成

这次给大家带来easyui的下拉框动态级联加载的实现方法(附代码),easyui下拉框动态级联加载的注意事项有哪些,下面就是实战案例,一起来看一下。

easyui的下拉框动态加载数据,高校中要根据首先查询所有学院,然后根据学院动态加载课程。下面看如何实现。

1.界面效果

f780a216cea14674a26a3961a6699088.png

2. html + js代码学院名称:

课程名称:


$(function() {

// 下拉框选择控件,下拉框的内容是动态查询数据库信息

$('#collegeName').combobox({

url:'${pageContext.request.contextPath}/loadInstitution',

editable:false, //不可编辑状态

cache: false,

panelHeight: '150',

valueField:'id',

textField:'institutionName',

onHidePanel: function(){

$("#courseName").combobox("setValue",'');//清空课程

var id = $('#collegeName').combobox('getValue');

//alert(id);

$.ajax({

type: "POST",

url: '${pageContext.request.contextPath}/loadCourse?id=' + id,

cache: false,

dataType : "json",

success: function(data){

$("#courseName").combobox("loadData",data);

}

});

}

});

$('#courseName').combobox({

//url:'itemManage!categorytbl',

editable:false, //不可编辑状态

cache: false,

panelHeight: '150',//自动高度适合

valueField:'id',

textField:'courseName'

});

});

3.后台代码@RequestMapping("/loadInstitution")

/**

* 加载学院

* @param

* @param

* @return void

* @exception/throws [违例类型] [违例说明]

* @see [类、类#方法、类#成员]

* @deprecated

*/

public void loadInstitute(HttpServletRequest request,

HttpServletResponse response) throws Exception {

try {

JackJsonUtils JackJsonUtils = new JackJsonUtils();

List institutionList = institutionBean

.queryAllColleage();

System.out.println("学院list大小=====" + institutionList.size());

String result = JackJsonUtils.BeanToJson(institutionList);

System.out.println(result);

JsonUtils.outJson(response, result);

} catch (Exception e) {

logger.error("加载学院失败", e);

}

}

@RequestMapping("/loadCourse")

/**

* 动态加载课程

*

*

* @param

* @param

* @return void

* @exception/throws [违例类型] [违例说明]

* @see [类、类#方法、类#成员]

* @deprecated

*/

public void loadCourse(HttpServletRequest request,

HttpServletResponse response) throws Exception {

JackJsonUtils JackJsonUtils = new JackJsonUtils();

String id = request.getParameter("id");

System.out.println("学院id====" + id);

try {

if(id != null && id != ""){

List listCourseInfoList = courseBean

.queryAllCourseInfos(id);

System.out.println("课程list大小=====" + listCourseInfoList.size());

String result = JackJsonUtils.BeanToJson(listCourseInfoList);

System.out.println(result);

JsonUtils.outJson(response, result);

}

} catch (Exception e) {

logger.error("加载课程失败", e);

}

}

根据基础提供的接口查询学院和课程,转换为json格式后绑定到前台控件上。

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值