Pass an array to typehhead Bootstrap

I am trying to pass an array of values ​​through json to the source:Typeahead Bootstrap plugin parameter .

Here is my simple code: JsFiddle

I have a JSON object and I would like to pass only the id value tosource: array

What am I doing wrong ... I've tried a lot of things.

+3
source share
2 answers

Twitter typeahead expects a Javascript array type. Thus, you will need to convert the JSON object to a legitimate array using JSON.parse(myJSONObject). However, typeahead also expects an array of strings, not an array of arrays ... So the question is: what parameter of these arrays are you trying to show in typeahead?

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

, vals id. , source x. jsFiddle:

+4

local.

typeahead, .

.

var data = ["john", "terry", "phil","stuart","louis","marie","bob"];

$("#user-search").typeahead({
   name: "user-search",
   local: data,
   limit: 10
});
+1

Source: https://habr.com/ru/post/1588889/


All Articles