Выберите2 в изменении
<script>
$('#exampleSelect2').select2().on('change', function(){
// ...
});
</script>
hirohito
<script>
$('#exampleSelect2').select2().on('change', function(){
// ...
});
</script>
$('#mySelect2').on('select2:select', function (e) {
var data = e.params.data;
console.log(data);
});
//Initialize Select2 Elements
$('#select2-positions').select2().on("change", function (e) {
console.log($(this).val())
});
//other events
//https://select2.org/programmatic-control/events
any .val() updates need to be followed by
$('#unit').val('21'); // Select the option with a value of '21'
$('#unit').trigger('change'); // Notify any JS components that the value changed
var options = [];
$.each(dataReturn, function (i, obj) {
//console.log(i);
//console.log(obj);
options.push({
text: obj.NickName,
id: obj.NickName
});
})
$("#BeneType").empty().select2({
data: options
});