我正在使用带有 ajax 的打字头进行自动完成。在进行搜索时,我遇到了不需要的过滤器。
例如,当我搜索“回到 future ”时,就可以了。
但是当我搜索“Future Back”时,我也期待看到 -> “回到 future ”
$('.ajax-typeahead').typeahead({
source: function (query, process) {
return $.post('http://www.ilanlarnette.net/autocomplete/lokasyon', { lokasyon: query }, function (data) {
objects = [];
map = {};
$.each(data, function(i, object) {
map[object.label] = object;
objects.push(object.label);
});
return process(objects);
});
},
items: 15,
updater: function (item) {
alert("selected "+item+" "+map[item].id+" "+map[item].mahalle+" "+map[item].ilce);
}
});
工作示例可以找到 here
即使它在搜索结果集中。结果未显示在 typehead 中的下拉菜单。
最佳答案
当我在 jsfiddle 示例中输入 future
时,我看到后端相关错误,我认为您应该首先修复该错误。
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined variable: lokasyon_arrays</p>
<p>Filename: controllers/autocomplete.php</p>
<p>Line Number: 34</p>
</div>null
就像Rocket Hazmat所说,您需要为您的预输入实现自定义匹配器,因此它看起来像这样。
yourInput.typeahead({
source: yourSource,
matcher: function(item) {
// The 'item' parameter is any item in your list (e.g. "Pizza" )
// Use this.query to access the search string (e.g. "I want a Pizza")
// return true if this.query matches item through your custom logic
}
});
关于javascript - 如何防止通过 Twitter Bootstrap Typeahead 过滤结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17553765/