Dr.*_*ini 6 javascript json 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",
"count": 4,
"results": {
"1": {
"term": "Losanna"
},
"2": {
"term": "Losone"
},
"3": {
"term": "Lostallo"
},
"4": {
"term": "Lostorf"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
你看错了吗?谢谢!
Dr.*_*ini 12
这是为了确认问题是由这个类型的bug引起的:https://github.com/twitter/typeahead.js/issues/1218
正如joekur在问题报告中所建议的,我解决了这个问题:
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));
Run Code Online (Sandbox Code Playgroud)
有了这个:
suggestions = suggestions.slice(0, that.limit - rendered);
rendered += suggestions.length;
that._append(query, suggestions);
Run Code Online (Sandbox Code Playgroud)
我将自己的问题标记为重复:TypeAhead.js和Bloodhound显示奇数个结果这是同样的问题,我之前因为不同的措辞而找不到它
HTH.
| 归档时间: |
|
| 查看次数: |
4619 次 |
| 最近记录: |