如何防止通过Twitter Bootstrap'过滤结果;s打字机

How to prevent filtering results via Twitter Bootstrap's Typehead?

本文关键字:过滤 结果 打字机 何防止 Twitter Bootstrap      更新时间:2023-09-26

我使用带有ajax的typehead来自动完成。在进行搜索时,我会遇到不需要的过滤器。

例如,当我搜索"回到未来"时,它是可以的。

但当我搜索"Future Back"时,我也期待看到->"回到未来"

 $('.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);
    }
});

工作示例可以在这里找到

甚至在搜索结果集中。结果不会显示在打印头下拉菜单中。

当我在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
    }
});