So I'm using typeahead for suggestions while typing. All is working like a charm except for one thing: It only shows results. I'm using a remote search. When i go directly to the page it displays 10 results like expected (query set to max 10 rsults). If i alert data.length from bloodhound it also shows 10 search results. I have checked via alert on the begining and alert on the ending if there was something wrong but all alerts where ok.
Here is my JQ:
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;
}
}
});
The JSON i get back is as follows:
[{"ID":"266","barcode":"8711577077020","artikelNaam":"(combi)magnetronreiniger","artikelMerk":"HG","inhoud":"500","type":"ml","foto":"0","vers":"0","voorraadID":null},
{"ID":"329","barcode":"8710400307549","artikelNaam":"3 Laags Tissues","artikelMerk":"Albert Heijn","inhoud":"80","type":"stuks","foto":"0","vers":"0","voorraadID":"188"},
{"ID":"261","barcode":"5000204676150","artikelNaam":"5in1 Laminaatreiniger","artikelMerk":"Pledge","inhoud":"750","type":"ml","foto":"0","vers":"0","voorraadID":null},
{"ID":"14","barcode":"8718452111725","artikelNaam":"8 Goudeerlijk Witte Bollen","artikelMerk":"Jumbo","inhoud":"8","type":"stuks","foto":"0","vers":"0","voorraadID":null},
{"ID":"337","barcode":"8710400504498","artikelNaam":"Aardappelschijfjes Voorgekookt","artikelMerk":"Albert Heijn","inhoud":"450","type":"g","foto":"0","vers":"0","voorraadID":"195"},
{"ID":"72","barcode":"8718449034150","artikelNaam":"Acacia Honing","artikelMerk":"Jumbo","inhoud":"350","type":"g","foto":"0","vers":"0","voorraadID":null},
{"ID":"338","barcode":"5410036501726","artikelNaam":"Allesreiniger ","artikelMerk":"Dettol","inhoud":"1","type":"l","foto":"0","vers":"0","voorraadID":null},
{"ID":"283","barcode":"8710400771753","artikelNaam":"Appelsap uit Geconcentreerd Sap","artikelMerk":"Albert Heijn","inhoud":"1","type":"l","foto":"0","vers":"0","voorraadID":null},
{"ID":"315","barcode":"8718449066762","artikelNaam":"Augurken Fijn","artikelMerk":"Jumbo","inhoud":"340","type":"g","foto":"0","vers":"0","voorraadID":null},
{"ID":"40","barcode":"5410231103404","artikelNaam":"Backin Baking Powder","artikelMerk":"Dr. Oetker","inhoud":"5","type":"stuks","foto":"0","vers":"0","voorraadID":null}]
Also when searching other query's it gives back 5 results only in the dropdown. Hope someone has some clue about what is wrong with it.
Aucun commentaire:
Enregistrer un commentaire