What I\'m trying to do is to get a json object via Ajax and populate the Bootstrap Typeahead with just one kind of value.
Here is my code:
nameTypeHe
I made it from scratch:
$('#typeahead').typeahead({
source: function (query, process) {
return $.getJSON(
'path/to/lookup',
{ query: query },
function (data) {
return process(data);
});
}
});
Where data is a simple JSON array like:
[
"John",
"Jane",
"Alfredo",
"Giovanni",
"Superman"
]
If your data array has got a different structure, just rearrange it before passing it to process() method.
You can find a live example here.
EDIT - based on your json data:
[
{'id':'0', 'name':'John'},
{'id':'1', 'name':'Jane'},
{'id':'2', 'name':'Alfredo'},
...
}
The getJSON callback becomes:
function (data) {
var newData = [];
$.each(data, function(){
newData.push(this.name);
});
return process(newData);
});