我的Typeahead.js /血犬(0.11.1)并不像预期的那样工作。在提供的json结果的长列表中,只有一些显示为建议。
例如,如果我在我的字段中键入los,当应该显示4个可选项时,我只会得到Lostorf,而不会得到任何其他内容。
这是我的密码:
<div id="remote">
<input class="typeahead" type="text">
</div>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()
})Json
{
"data": {
"query": "los",
"count": 4,
"results": {
"1": {
"term": "Losanna"
},
"2": {
"term": "Losone"
},
"3": {
"term": "Lostallo"
},
"4": {
"term": "Lostorf"
}
}
}
}你看到什么不对劲了吗?谢谢!
发布于 2015-05-21 10:34:30
这是为了确认问题是由typehaead:https://github.com/twitter/typeahead.js/issues/1218引起的
正如joekur在问题报告中所建议的那样,我解决了以下问题:
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));在这方面:
suggestions = suggestions.slice(0, that.limit - rendered);
rendered += suggestions.length;
that._append(query, suggestions);我把我自己的问题标为重复:TypeAhead.js and Bloodhound showing an odd number of results
HTH。
https://stackoverflow.com/questions/30370496
复制相似问题