javascript - 如何防止通过 Twitter Bootstrap Typeahead 过滤结果?

标签 javascript jquery twitter-bootstrap typeahead

我正在使用带有 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/

相关文章:

javascript - 使用 JavaScript 在适当的 HTML 中包装 markdown

javascript - PhantomJS 无法在 JavaScript 页面上运行,错误 "Activate JavaScript"

javascript - 通过 JQuery 调用不显示 Bootstrap 模态窗口

html - 居中 Bootstrap 响应列

javascript - 如何检查默认的JS对象是否被修改?

javascript - 给定一个整数数组,找到具有最大乘积的一对相邻元素并返回该乘积

javascript - 获取下拉列表中选定的项目不起作用

javascript - 预览后打印媒体查询不隐藏类

jquery - 如何更改导航选项卡的背景颜色

javascript - bootstrap3-datetimepicker-rails 显示问题