Search 推特';It’我们建议提前订购

Search 推特';It’我们建议提前订购,search,twitter,typeahead,bloodhound,Search,Twitter,Typeahead,Bloodhound,目前的问题是,搜索建议的顺序与图片中显示的起始字符不同: 我如何解决这个问题 下面是我的代码`$(document).ready(function() { //var=银行 var queries = ['there is no need', 'need', 'no need', 'ne']; //Dataset defined in index.php // ***** //(NOTE: Typehead works by the order of the elements in datas

目前的问题是,搜索建议的顺序与图片中显示的起始字符不同:

我如何解决这个问题

下面是我的代码`$(document).ready(function() { //var=银行

var queries = ['there is no need', 'need', 'no need', 'ne'];

//Dataset defined in index.php
// *****
//(NOTE: Typehead works by the order of the elements in dataset, thus
//          they are ordered in the database first based on count)

//Constructing the suggestion engine
var queries = new Bloodhound(
    {
        datumTokenizer: Bloodhound.tokenizers.whitespace,
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        local: queries
    });

// Initializing the typeahead (.typehead is the selector having what's currently
//                                  being typed)
$('.typeahead').typeahead(
    {
        hint: true,
        highlight: true, /* Enable substring highlighting */
        minLength: 1 /* Specify minimum characters required for showing result */
    },
    {
        name: 'queries',
        source: queries
    });

}))`

如果使用函数初始化了
sorter
属性,
Bloodhound
将使用它对匹配的条目进行排序,如下所示:

var queries = new Bloodhound(
{
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    local: queries,
    sorter: function(a, b) {
        if (a < b) {
            return -1;
        }
        else if (a > b) {
            return 1;
        }
        else return 0;
    }
});
var querys=新猎犬(
{
datumTokenizer:Bloodhound.tokenizers.whitespace,
queryTokenizer:猎犬,标记,空白,
本地:查询,,
分拣机:功能(a、b){
if(ab){
返回1;
}
否则返回0;
}
});
因此,只需扩展
猎犬
的初始化,就可以开始了