我正在使用带有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) 这似乎是一个标准的事情,但我很难找到一个清晰简单的解决方案.
我希望能够为已经初始化的Select2添加一个或多个附加选项.
我使用的是旧版本的Select2,但不确定版本是什么.