【发布时间】:2018-03-10 02:07:44
【问题描述】:
根据文档,我应该可以通过 select 标签上的 data-attributes 设置一些配置。
https://select2.org/configuration/data-attributes
在我的代码中,我尝试了这个:
<select id="customer_select_form_customer" name="customer_select_form[customer]" class="select2-ajax-enabled form-control" style="width: 500px" data-theme="bootstrap4" data-ajax--url="/customer/ajaxList" data-ajax--cache="true" data-select2-id="customer_select_form_customer" ></select>
我尝试使用以下内容对其进行初始化,但它什么也没做:
// enable the customer ajax list
$('.select2-ajax-enabled').select2({});
我也尝试设置参数,并让它们覆盖,但这也没有用:
// enable the customer ajax list
$('.select2-ajax-enabled').select2({
theme: 'bootstrap4',
minimumInputLength: 3,
ajax: {
url: '',
dataType: 'json',
cache: 'true'
}
});
我是否缺少使数据属性正常工作的配置/设置? 如果我指定整个配置并将其传递给 select2,它会按预期工作。
我正在使用 jQuery v3.3.1 和 Select2 4.0.6-rc.1
【问题讨论】:
标签: javascript jquery jquery-select2