easyUI combobox实现联动效果

2020-05-24 21:42:06易采站长站整理

$("#type").combobox({
valueField: 'value',//值字段
textField: 'text',//显示的字段
data: typeData,
panelHeight: 170,
onSelect: function() {
var myOptValue = $("#type").combobox("getValue");
//1.清空原来的classify这个combobox中的选项
$("#classify").combobox("clear");
//2.动态添加"操作类型"的下拉列表框的option
if (myOptValue != null && (myOptValue == 'prodName' || myOptValue == 'prodStatus')) {
console.info("myOptValue = " + myOptValue);
$("#classify").combobox({
panelHeight: 50,
data: options01
});
} else {
$("#classify").combobox({
panelHeight: 140,
data: options02
});
}
//3.清空文本输入框——用户输入的条件
//$("#userInputCondition").val("");
}
});
//初始化classify的下拉列表
$("#classify").combobox({
valueField: 'value',
textField: 'text',
data: options02,
panelHeight: 140,
});
});

下面是一个关于省市区的联动:


var h = $(window).height() * 0.65;
// 省级
$('#province').combobox({
valueField: 'name', //值字段
textField: 'name', //显示的字段
url: '/TidewaySHPServer/area/findAllProvince',//url为java后台查询省级列表的方法地址
panelHeight: h,
editable: true,
//模糊查询
filter: function(q, row) {
var opts = $(this).combobox('options');
return row[opts.textField].indexOf(q) == 0; //从头匹配,改成>=即可在任意地方匹配
},
onSelect: function(rec) {
$('#city').combobox('setValue', "");
$('#county').combobox('setValue', "");
var url = '/TidewaySHPServer/area/findAllCity?parentId=' + rec.areaId;//url为java后台查询事级列表的方法地址
$('#city').combobox('reload', url);
}
});
//市区
$('#city').combobox({
valueField: 'name', //值字段
textField: 'name', //显示的字段
panelHeight: 'auto',
editable: false, //不可编辑,只能选择
value: '',
onSelect: function(rec) {
$('#county').combobox('setValue', "");
var url = '/TidewaySHPServer/area/findAllDistrictOrCounty?parentId=' + rec.areaId;//url为java后台查询区县级列表的方法地址
$('#county').combobox('reload', url);
}
});
//区 县
$('#county').combobox({
valueField: 'areaId',
textField: 'name',
panelHeight: 'auto',
editable: false,
});

基本上想写的都写完了,主要是多个combobox的联动效果,写的不完美大家相互学习一下