Created by: mlmorg
This is a simple change to allow both synchronous and asynchronous data sources for the typeahead widget via a function/callback. This references issue #1336 (closed). Example:
$("input").typeahead({
source: function (query, process) {
$.get('/autocomplete', { q: query }, function (data) {
process(data)
})
}
})
Because of the recently-added "updater" option, you can also handle objects:
var labels
, mapped
$("input").typeahead({
source: function (query, process) {
$.get('/autocomplete', { q: query }, function (data) {
labels = []
mapped = {}
$.each(data, function (i, item) {
mapped[item.label] = item.value
labels.push(item.label)
})
process(labels)
})
}
, updater: function (item) {
return mapped[item]
}
})