相关疑难解决方法(0)

Typeahead.js/Bloodhound只显示一个结果

我的Typeahead.js/Bloodhound(0.11.1)没有按预期工作.在提供的json结果列表中,只有一些显示为建议.

例如,如果我输入los我的字段,那么只有Lostorf4个可选项显示时,我才会得到其他内容.

这是我的代码:

HTML

<div id="remote">
<input class="typeahead" type="text">
</div>
Run Code Online (Sandbox Code Playgroud)

JS

var searchablePlaces    = new Bloodhound({
    datumTokenizer      : Bloodhound.tokenizers.obj.whitespace("term"),
    queryTokenizer      : Bloodhound.tokenizers.whitespace,
    remote              : {
        url             : 'http://www.example.com/autocomplete/%QUERY/',
        wildcard        : '%QUERY',
        filter          : function(response) { return response.data.results; }
      },
    limit               : 10
});

searchablePlaces.initialize();

$('#remote .typeahead').typeahead(
{
    hint            : true,
    highlight       : true,
    minLength       : 2
},
{
    name            : 'searchable-places',
    displayKey      : "term",
    source          : searchablePlaces.ttAdapter()
})
Run Code Online (Sandbox Code Playgroud)

JSON

{
    "data": {
        "query": "los", …
Run Code Online (Sandbox Code Playgroud)

javascript json typeahead.js bloodhound

6
推荐指数
1
解决办法
4619
查看次数

标签 统计

bloodhound ×1

javascript ×1

json ×1

typeahead.js ×1