I'm currently in the process of integrating typeahead.js into a search field, but I am encountering issues where async results are only displaying sporadically, whereas local results consistently work.
The JSON data returned by my suggestion backend looks like this:
[{
"query": "anders troelsen",
"hits": "1197",
"queryCount": "39"
},
{
"query": "anders fogh jensen",
"hits": "295",
"queryCount": "38"
}]
My objective is to convert the above JSON into an array of strings within the code and then display it. Here's the suggester code snippet:
var localSuggestResults = ["anders and", "anders ladekarl", "anders høg nissen"];
var searchSuggestions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: localSuggestResults,
remote: {
url: '/services/suggest?prefix=%QUERY',
wildcard: '%QUERY',
transform: function (suggestions) {
var suggestionArray = suggestions.map(function(suggestion) {
return suggestion.query
});
return suggestionArray;
}
}
});
$("#query").typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
source: searchSuggestions
});
Do you have any tips on what might be causing the issue? Thank you for your help!