Javascript typeahead不会处理所有的猎犬结果
因此,我在打字时使用typeahead作为建议。除了一件事之外,一切都像一个魔咒一样起作用:它只显示结果。我正在使用远程搜索。当我直接转到该页面时,它会显示10个与预期相同的结果(查询设置为最多10个结果)。如果我从猎犬那里提醒data.length,它还会显示10个搜索结果。我已经在开始时通过alert进行了检查,在结束时通过alert进行了检查,如果出现了问题,但所有警报都正常 这是我的JQ:Javascript typeahead不会处理所有的猎犬结果,javascript,jquery,typeahead.js,Javascript,Jquery,Typeahead.js,因此,我在打字时使用typeahead作为建议。除了一件事之外,一切都像一个魔咒一样起作用:它只显示结果。我正在使用远程搜索。当我直接转到该页面时,它会显示10个与预期相同的结果(查询设置为最多10个结果)。如果我从猎犬那里提醒data.length,它还会显示10个搜索结果。我已经在开始时通过alert进行了检查,在结束时通过alert进行了检查,如果出现了问题,但所有警报都正常 这是我的JQ: var producten = new Bloodhound({ datumTokeniz
var producten = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 100,
remote: {
'cache': false,
url: 'ajax/mysite.php?query=%QUERY',
wildcard: '%QUERY',
filter: function (data) {
//alert(data.length); when alert is active it shows that the length is 10
return data;
}
}
});
producten.initialize();
var i=0 //Have this for the loops to check if all the alerts where coming trough
$('.menuTypeahead').typeahead({
highlight: true
}, {
name: 'menuZoek',
source: producten.ttAdapter(),
displayKey: 'artikelNaam',
templates: {
suggestion: function (producten) {
i++;
alert(i+".1"); //begin alert
var resultaat=''
if(producten.artikelNaam=='geen suggestie'){
resultaat='<strong>' + producten.artikelNaam + '</strong>';
} else {
if(producten.foto==1){
imgLink='img/'+producten.barcode+'.jpg';
} else {
imgLink='css/pics/no_image.jpg';
}
if(producten.vers==1){
$vers='(vers)';
} else {
$vers='';
}
$("#menuSearchLink").val("artikel.php?barcode="+producten.barcode);
resultaat= '<div>'+
'<a href="artikel.php?barcode=' + producten.barcode + '&refer='+temp+'">'+
'<div class="search-image">'+
'<img src="'+imgLink+'" style="height:50px;width:auto">'+
'</div>'+
'<div style="min-height:50px;">'+
'<strong>' + producten.artikelNaam + ' '+$vers+'</strong>' +
'<br>' + producten.inhoud + ' ' + producten.type + ' - ' + producten.artikelMerk +
'</div>'+
'</a>'+
'</div>';
}
alert(i+".2"); //end alert
return resultaat;
}
}
});
此外,当搜索其他查询时,它只在下拉列表中返回5个结果。希望有人能知道它到底出了什么问题。在进一步搜索之后,我无意中发现了另一篇stackoverflow文章和Github上的一个问题。我提到的问题现在是Github的一个已知问题 堆栈溢出: Github: 还了解到typeahead现在最多只能显示5个结果。更改了这段代码:
$('.menuTypeahead').typeahead({
highlight: true
}, {
name: 'menuZoek',
source: producten.ttAdapter(),
displayKey: 'artikelNaam',
limit: 10, //new piece of code
templates: {
$('.menuTypeahead').typeahead({
highlight: true
}, {
name: 'menuZoek',
source: producten.ttAdapter(),
displayKey: 'artikelNaam',
limit: 10, //new piece of code
templates: {