Trigger The Typeahead Event Programmatically Using Jquery
I'm using bootstrap and working with typeaheads. I can set type aheads for an input field using: var subjects = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3'
Solution 1:
The requested feature is already built into the typeahead library, it allows the source to be a function as given the the documentation as given below
$('#search-field').typeahead({
source: function(query, process){
$.getJSON('http://localhost:8983/solr/suggest/?q='+ query +'&wt=json&json.wrf=?', {
}).done(function(response){
var suggestions=[];
$.each(response.spellcheck.suggestions[1].suggestion, function(){
// add the suggestions into the array
suggestions.push(this);
});
process(suggestions)
});
}
});
Post a Comment for "Trigger The Typeahead Event Programmatically Using Jquery"