Jquery typeahead.js未返回所有结果
我在让typeahead.js返回/呈现页面上的所有结果时遇到问题。这是我的密码:Jquery typeahead.js未返回所有结果,jquery,jquery-plugins,typeahead.js,Jquery,Jquery Plugins,Typeahead.js,我在让typeahead.js返回/呈现页面上的所有结果时遇到问题。这是我的密码: var places = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/api/place/?country={{ country.id }}&n
var places = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/place/?country={{ country.id }}&name=%QUERY'
, transform: function (data) {
return data.response;
}
, wildcard: '%QUERY'
}
});
var selected = false;
$('.typeahead-place').typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'places',
displayKey: function (obj) {
if (obj.url != null && obj.url.length && (obj.street == null || obj.street.length == 0)) {
return obj.name + " (Online store)";
}
return obj.name + " (" + obj.street + ", " + obj.city + ", " + obj.postcode + ")";
},
source: places
});
Punn
的示例查询从服务器返回JSON,如下所示:
{
"response": [
{
"id": "4",
"name": "Punnitse ja Säästä 2",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "12",
"name": "Punnitse ja Säästä 3",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "13",
"name": "Punnitse ja Säästä 4",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "9",
"name": "Punnitse ja Säästä Kamppi",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
}
]
}
现在,这呈现为:
这似乎是新版本的typeahead.js
的一部分。为了使代码正常工作,您最好切换到版本0.10.5或更低,并稍微转换代码:
var places = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/place/?country={{ country.id }}&name=%QUERY',
wildcard: '%QUERY',
filter: function(data) { // <-- should use `filter`
return data.response;
}
}
});
places.initialize(); // <-- initialise suggestion
$('.typeahead-place').typeahead({
hint: true,
highlight: true,
minLength: 2
}, {
name: 'places',
source: places.ttAdapter(), // <-- get adapter as a source
displayKey: function(obj) {
// ...
}
});
var places=新猎犬({
datumTokenizer:Bloodhound.tokenizers.whitespace,
queryTokenizer:猎犬,标记,空白,
远程:{
url:“/api/place/?country={{country.id}}&name=%QUERY”,
通配符:“%QUERY”,
filter:function(data){/我在这里找到了答案:由以下人员提供:
…也就是说,您需要设置Javascript全局无限属性的限制。这完全有效
这就是说,他们还没有修补代码是一种犯罪,这个错误已经被发现很多年了。修补程序中有错误^^^应该在typeahead.bundle.js:suggestions=suggestions.slice(0,That.limit-rendered)中再删除一行@StavBodik您已经不再提到bug了哇,现在是2020年,这仍然是一个问题。我刚刚使用了上面链接的补丁@VisioN,它工作得非常好。
...
$('.typeahead-place').typeahead({
hint: true,
highlight: true,
minLength: 2,
limit: Infinity
},
...