twitter/bootstrap — pull request #3682 by mlmorg (2012-06-03 04:35:40+00:00)
Title: Alter typeahead to accept synchronous/asynchronous data source

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