[英]How to configure Select2 via data-* attributes
根据文档,我应该能够通过select标记上的数据属性设置一些配置。
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
继续进行此操作,因为我找到了答案:由于v4.0.6上的错误,此方法不起作用。 我恢复到v4.0.5,并且它使用的是我在初始帖子中包含的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.