相关疑难解决方法(0)

使用AJAX插入后,在Select2中设置数据

我正在使用带有AJAX的Select2(下面的代码):

$(".select2-ajax").select2({
        placeholder: "Search user",
        minimumInputLength: 1,
        ajax: {
            url: $('#url-search-client').val(),
            dataType: 'json',
            type: 'post',
            data: function (term, page) {
            return {
                filter: term
            };
            },
            results: function (data, page) {
            return {results: data};
            }
        },
        width : '50%',
        formatInputTooShort: function () {return 'Informe mais caracteres'; },
        formatResult: formatResultSelectAjax, // omitted for brevity, see the source of this page
        formatSelection: formatSelectAjaxValue, // omitted for brevity, see the source of this page
        dropdownCssClass: "bigdrop" // apply css that makes the dropdown …
Run Code Online (Sandbox Code Playgroud)

ajax jquery jquery-select2

10
推荐指数
2
解决办法
3万
查看次数

在初始化后向Select2添加选项

这似乎是一个标准的事情,但我很难找到一个清晰简单的解决方案.

我希望能够为已经初始化的Select2添加一个或多个附加选项.

我使用的是旧版本的Select2,但不确定版本是什么.

jquery-select2

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

jquery-select2 ×2

ajax ×1

jquery ×1