typeahead set array key value pair

411 views Asked by At

I am using typeahead and it is working well on load. When I type something the input shows the suggestions very nicely. My result set is a json encoded array:

{"10495":"DNEARWO"}

Now, I have a situation where user selects another field and the call is made to database based on the user selection and the value must be set to the typeahead based on the database result. I am unable to set the value of the typeahaed. I am using this piece of code:

$('#typehead').eq(0).val('val', response);
$('#typehead').typeahead('val', response).trigger("input");
$('#typehead').val('val', response);

Nothing seems to work. The response is the json encoded array shown above. Any help on how can I set the key value pair dynamically and that should be displayed. Note that typeahead is initialized on page load.

The Request: enter image description here

The Response: enter image description here

0

There are 0 answers