I am trying to use the Typeahead and bloodhound framework to search a response of api paths, from a remote API call.
by example url api.example.com/getEndpoints I would receive an object containing all the endpoints. I'd want the typeahead to filter those endpoints. As far as I understand you want to specify a query when using the remote, which I obviously can't, as I just receive all the endpoints in one request.
Is there any way, or suggestion, to solve this issue?
My code would look something like
// Instantiate the Bloodhound suggestion engine
var endpoints = new Bloodhound({
datumTokenizer: function (datum) {
console.log('datumTokenizer, datum: ', datum, ', datum.value: ', datum.value);
return Bloodhound.tokenizers.whitespace(datum.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://api.example.com/getEndpoints',
filter: function (endpoints) {
console.log(endpoints);
// Map the remote source JSON array to a JavaScript object array
return Object.keys(endpoints).map(function (endpointPath) {
console.log(endpointPath);
return {
value: endpointPath
};
});
}
},
limit: 10
});
// Initialize the Bloodhound suggestion engine
endpoints.initialize();
// Instantiate the Typeahead UI
$('#inputPath').typeahead(
{
hint: true,
highlight: true,
minLength: 1
}, {
displayKey: 'value',
source: endpoints.ttAdapter()
}
);