Example Typeahead.js Computed
HTML
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
<input id='sync_typeahead' placeholder="synchronous" />
<input id='async_typeahead' placeholder="asynchronous" />
JavaScript
function sync(q) {
return ['Canada', 'China', 'Mexico', 'Brazil'];
}
function async(q, done) {
setTimeout(function () {
done(['Ukraine', 'Brazil', 'Zambia']);
}, 10);
}
$('#async_typeahead').typeahead({
computed: async,
});
$('#sync_typeahead').typeahead({
computed: sync,
});