twitter/bootstrap — pull request #3250 by mlmorg (2012-04-26 18:46:06+00:00)
Title: Alter typeahead to accept synchronous/asynchronous data source

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. Example:

```js
$("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:

```js
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]
}
})
```