簡體   English   中英

如何通過data- *屬性配置Select2

[英]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,並且它使用的是我在初始帖子中包含的代碼。

供參考: https : //github.com/select2/select2/pull/5169

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM