javascript - ajax-bootstrap-select 是否支持 liveSearch?
问题描述
我有一个基本的下拉菜单,它使用 bootstrap-selectpicker 库使用包含格式搜索下拉选项,我使用 ajax-bootstrap-select 插件https://github.com/truckingsim/Ajax-Bootstrap-Select填充下拉选项 ,我是试图找到一种方法来使用“包含”操作来搜索 ajax 填充的下拉选项,就像在原始 selectpicker 中一样。
我以前只使用 selectpicker,最近才使用 ajax 插件,我不确定插件的功能是否只是从“url”中获取选项。或者如果它从填充的选项中进行搜索并且我在编码时错过了任何参数。
<select class="selectpicker" multiple data-selected-text-format="count" data-actions-box="true" data-live-search="true" data-show-tick="false" data-live-search-style="contains">
</select>
<script>
var options = {
ajax: {
url: '/Search/Typeahead',
type: 'POST',
dataType: 'json',
data: function () {
var params = {
q: '{{{q}}}'
};
return params;
}
},
locale: {
emptyTitle: 'Select and Begin Typing'
},
preprocessData: function (data) {
var i, l = data.length, array = [];
if (l) {
for (i = 0; i < l; i++) {
var curr = data[i];
array.push({
'value': curr.value,
'text': curr.text,
'disabled': curr.disabled,
'selected': curr.selected,
});
}
}
return array;
},
preserveSelected: false
};
$('select.selectpicker').selectpicker({liveSearch: true }).ajaxSelectPicker(options);
$('.bootstrap-select').selectpicker();
//The dropdown options are not displayed at all if I use **.filter('.with-ajax')** as below:
//$('select.selectpicker').selectpicker({liveSearch: true }).filter('.with-ajax').ajaxSelectPicker(options);
//Also tried using <select class="selectpicker **with-ajax** " but it doesn't work for me either
$('select.selectpicker').trigger('change');
</script>
我有 ajax 填充选项,但搜索关键字不会改变下拉选项。
解决方案
尝试
$('.bootstrap-select').selectpicker('refresh');
代替
$('.bootstrap-select').selectpicker();
有时您可以使用检查器看到 HTML 中的更改,并且需要selectpicker
在更改后刷新。
推荐阅读
- c# - CSRF 测试在 ASP.NET MVC 应用程序中失败
- sql - 两个表格枢轴显示用户类型和分配角色的矩阵
- tomcat - Intellij Idea远程tomcat服务器配置
- phabricator - 如何在共享主机上安装 phabricator?
- python - Python SQLite:IndexError:列表索引超出范围
- c++ - 如何知道 QDataStream 不能反序列化某些东西?
- android - Android 8,登录时每个用户的ANDROID_ID值不同吗?
- java - 重新启动活动时要调用的 onStop 延迟
- javascript - 无法加载 iFrame CSS
- c - c - 带有随机打印的空指针数组