Bootstrap TypeAhead with JSON data
Bootstrap TypeAhead with JSON data
by Alexandru Mihai
HTML
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css">
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script>
<script src="https://rawgithub.com/bassjobsen/Bootstrap-3-Typeahead/master/bootstrap3-typeahead.js"></script>
<input id='example'/>
JavaScript
$('#example').typeahead( {
source: function (query, response) {
return $.get('https://jsonplaceholder.typicode.com/posts', { query: query }, function (data) {
console.log(data);
return response(data);
});
},
displayText: function(item) {
return item.title
}
})