1. 程式人生 > >關於easyUI的combbobox下拉框多選時,後臺獲取下拉框的值獲取的問題

關於easyUI的combbobox下拉框多選時,後臺獲取下拉框的值獲取的問題

在使用easyUI的combobox時,當引數裡設定為multiple:true時,下拉框可以選擇多個,

js程式碼

<pre name="code" class="javascript">$('#cc').combobox({
		 panelHeight:'auto',
         multiple:true,
		method:'get',
		url:'web',
		dataType : "json",
		valueField:'id',
		textField:'name',
			
        });


前臺html程式碼:

<input name = "catalog_id" id="cc"  />


多選時,值的獲取不是一個String了,是一個String[] 的陣列了,此時後臺獲取應該是

String[] catalog_id = req.getParameterValues("catalog_id");

設定多選的combox的值時,
$('#cc').combobox('setValues','value1','value2');

使得combobox自帶複選框功能則可以使用以下程式碼:
$('#cc').combobox({
                url:'combobox_data1.json',
                method:'get',
                valueField:'id',
                textField:'text',
                panelHeight:'auto',
                multiple:true,
                formatter: function (row) {
                    var opts = $(this).combobox('options');
                    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]
                },
                onLoadSuccess: function () {
                    var opts = $(this).combobox('options');
                    var target = this;
                    var values = $(target).combobox('getValues');
                    $.map(values, function (value) {
                        var el = opts.finder.getEl(target, value);
                        el.find('input.combobox-checkbox')._propAttr('checked', true);
                    })
                },
                onSelect: function (row) {
                    //console.log(row);
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', true);
                },
                onUnselect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', false);
                }
            });