I have an ajax route which respond a json array with sites which gets it from a txt file. In my twig template Im using typeahead function to do an ajax call like:
var sites= new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '{{'ajax_fun'}}'
});
$('#bloodhound .typeahead').typeahead({
name: 'sites',
source: sites
});
The filtering on input field does not work even thought i get the array with the sites.
In case someone want to know how to populate states with json array getting from remote path this was my solution:
var states = [];
var statesBloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// `states` is an array of state names defined in "The Basics"
local: states
});
//populate the statesBloodhound
$.getJSON('path', {
}).done(function(data){
statesBloodhound.add(data);
})
$('#bloodhound .typeahead').typeahead({
name: 'statesBloodhound ',
source: statesBloodhound
});