Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass array to typeahead Bootstrap

I'm trying to pass via json an array of values to the source: option of Typeahead plugin of Bootstrap.

Here is my simple code: JsFiddle

I have a JSON object and I'd like to pass just the value id to the source: array

What I'm doing wrong... I tried many things.

like image 775
Ayeye Brazo Avatar asked Sep 26 '12 14:09

Ayeye Brazo


1 Answers

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:

  • http://jsfiddle.net/365Sf/
like image 84
Michael Schonfeld Avatar answered Oct 11 '22 14:10

Michael Schonfeld