Created by: mlmorg
@fat: From existing pull request (#3250) against 2.1.0-wip. Sorry for not submitting it against a *-wip branch earlier.
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]
}
})