我在使用select2时遇到问题。我想更改类别过滤器,但当追加select2中的数据不起作用时。有什么解决方案可以解决这个问题?
的数据
$(document).on('change', '#filterbySelect1', function (event) {
event.preventDefault();
var selectVal = $('#filterbySelect1').val();
if (selectVal == 'categoryBook') {
$('.filter').append('<div class="form-group mb-5">'
+ '<label for="selectbyCategory">Filter Berdasarkan Katagori</label>'
+ '<select class="select2bs4" multiple="multiple" data-placeholder="Pilih Kategori" style="width: 100%;">'
+ '<option>Alabama</option>'
+ '<option>Alaska</option>'
+ '</select>'
+ '<small id="emailHelp" class="form-text text-muted">Maksimal memilih 3 kategori</small>'
+ '</div>');
}
});
//Initialize Select2 Elements
$('.select2').select2();
//Initialize Select2 Elements
$('.select2bs4').select2({
theme: 'bootstrap4',
dropdownParent: $('.filter')
});
字符串
1条答案
按热度按时间q1qsirdb1#
当你重新创建新的select时,在select2创建的情况下初始化:
字符串