我使用Selec2框架通过ajax调用来完成此操作,我在我的项目中成功实现了这一点,但为什么在输入值时搜索它会将当前搜索值显示为可选择的选项,即使没有结果,我也不想隐藏它。有什么建议吗?感谢
HTML:
<select style='width:100%;' id='select-employee'></select>
JS:
$("#select-employee").select2({
theme: "bootstrap",
placeholder: "Select employee...",
minimumInputLength: 1,
tags: [],
ajax: {
url: "getEmployee.php",
dataType: "json",
type: "POST",
delay: 250,
data: function(params) {
return {
term: params.term,
page: params.page
};
},
processResults: function(data, params) {
params.page = params.page || 0;
return {
results: data.items,
pagination: {
more: (data.page == "1" ? true : false)
}
};
},
cache: true
}
});
答案 0 :(得分:2)
嗨,因为您必须将代码填充为false,尝试将[]
更改为false
$("#select-employee").select2({
theme: "bootstrap",
placeholder: "Select employee...",
minimumInputLength: 1,
tags: false,
ajax: {
url: "getEmployee.php",
dataType: "json",
type: "POST",
delay: 250,
data: function(params) {
return {
term: params.term,
page: params.page
};
},
processResults: function(data, params) {
params.page = params.page || 0;
return {
results: data.items,
pagination: {
more: (data.page == "1" ? true : false)
}
};
},
cache: true
}
});