Select2 显示当前搜索的值
Select2 Show Currently Searched Value
我正在使用 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
}
});
您好,这是因为您必须将标签填充为 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
}
});
我正在使用 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
}
});
您好,这是因为您必须将标签填充为 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
}
});