English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Easyui combination box value and assignment

Recently, due to work needs, users can try the multi-select effect by clicking the dropdown box, and the effect is roughly as shown in the figure below:

The code that implements it is as follows:

<select id="iweekDay" class="col-sm-4 form-control easyui-combobox " name="state" data-options="multiple:true,multiline:true" style="width:350px;height:35px" >
<option value="1">1</option>
<option value="2">2</option> 
<option value="3">3</option> 
<option value="4">4</option> 
<option value="5">5</option> 
<option value="6">6</option> 
<option value="7">7</option> 
</select>

The most important thing is: multiple: true means that the dropdown box can be multi-selected. If it is single selection: multiple: false single selection

Below is a summary of the retrieval and assignment of combobox

2,Assignment

(1) Single-select assignment setValue

$('#Id').combobox('setValue','key')

(2) Multi-select assignment setValues

The multi-select key value is an array, $('#Id').combobox('setValues','key1,key2,key3'.split(','))

Note: 'key1,key2,key3'.split(',') splits the string into an array, because the second parameter of combobox is an array

3.retrieval

(1) Single-select retrieval getValue

$('#Id').combobox('getValue')

(2) Multi-select retrieval getValues

The multi-select key value is an array, $('#Id').combobox('getValues')

Note: The retrieved value is an array. If you want to convert it to a comma-separated string, for example (1,2,3Use the join method, the code is as follows:

var str=$('#Id').combobox('getValues').join(',');

PS: Let's take a look at the complete code for assignment and retrieval of easyui selectbox

Assignment and retrieval

// Redefine the banner
var storeName_value = '@ViewBag.StoreName';
var department_value = '@ViewBag.Department';
var changeDate_value = '@ViewBag.ChangeDate';
$('#StoreName option:selected').text(storeName_value); 
$('#Department option:selected').text(department_value);
//$('#StoreName').combobox('setValue', storeName_value);
//$('#Department').combobox('setValue', department_value);
// bind searchBtn
$('#this_submit').bind('click', function () {
// var st = $('#StoreName option:selected').text().trim();
// var dep = $('#Department option:selected').text().trim();
var st = $('#StoreName').combobox('getValue');
var dep = $('#Department').combobox('getValue');
var changeDate = $('#datepicker').val();
var href = '../';
href += '&storeName=' + st + '&department=' + dep + '&changeDate=' + changeDate;
href += '&page='1&size=8';
window.location.href = href;
});

The above is the combination box value and assignment of Easyui introduced by the editor, hoping it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. Also, I would like to express my heartfelt thanks to everyone for supporting the Yell Tutorial website!

You May Also Like