我的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)