select2的清空,当select2有值时,再使用初始化的方式赋值,会在原来的值后追加,需要使用和select一样的清空方式
$('.select2bs4').empty();
$('.sjksy').select2({
theme: 'bootstrap4',
ajax: {
url: '/aa/bbb/type/'+$("input[name='gzlx']:checked").val()+'/',
processResults: function (data) {
// Transforms the top-level key of the response object from 'items' to 'results'
return {
results: data.data
};
}
}
});
https://select2.org/data-sources/ajax