[英]Prevent ajax call on select2 click
How can I prevent ajax
call to retrieve select2
drop down items on click of select2
user interface element? 如何在单击
select2
用户界面元素时阻止ajax
调用来检索select2
下拉项? I want to retrieve select2
drop down items only when I type in search box. 我仅在输入搜索框时才想检索
select2
下拉项。 Any help would be most appreciated. 非常感激任何的帮助。
$("#ddlItems").select2({
minimumInputLength: 0,
width: '450px',
allowClear: true,
placeholder: "Select",
id: function (data) { return { id: data.Id }; },
ajax: {
quietMillis: 150,
url: getDataUrl,
dataType: 'json',
quietMillis: 100,
global: false,
data: function (term, page) {
return {
clientId: $("#clientID").val(),
pageSize: 20,
pageNum: page,
searchTerm: term
};
},
results: function (data, page) {
return { results: data.items, more: data.isSearchRemaining };
}
}
You have to change your minimumInputLength attribute. 您必须更改您的minimumInputLength属性。
Change it like that : 像这样改变它:
minimumInputLength: 1,
The ajax request is done when your input length >= minimumInputLength. 当您的输入长度> = minimumInputLength时,就完成了ajax请求。 So it is logical that when minimumInputLength = 0 , select2 will retrieve the data using the ajax :)
因此,当minimumInputLength = 0时,select2将使用ajax检索数据是合乎逻辑的:)
You have an example on here : https://select2.github.io/examples.html#data-ajax 您在此处有一个示例: https : //select2.github.io/examples.html#data-ajax
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.