Pass array to typeahead Bootstrap Pass array to typeahead Bootstrap json json

Pass array to typeahead Bootstrap


Twitter's typeahead is expecting a Javascript array type. So, you'll need to convert your JSON object to a legitimate array using JSON.parse(myJSONObject). However, typeahead is also expecting an array of strings, not array of arrays... So, the question is - which parameter of these arrays are you trying to show in the typeahead?

{    "id":"2",    "pid":"0",    "type":"Group",    "code":"g",    "status":"1"}

It looks like your vals function is isolating the id parameter. If that's the parameter you'd like typeahead to show, simply point source to x. Checkout this modified jsFiddle:


There is also the local property for this purpose.

You can use the local property in typeahead to provide an array without having to massage data.

e.g.

var data = ["john", "terry", "phil","stuart","louis","marie","bob"];$("#user-search").typeahead({   name: "user-search",   local: data,   limit: 10});