Search code examples
jqueryjsontwitter-typeahead

twitter typeahead does not work with my json


I do have a valid JSON-Feed like this:

[[21,"Adlikon"],[131,"Adliswil"]]

and I try to set the autocomplete with:

$('document').ready(function() {

  $('.city').typeahead({                                
      name: 'city',
      remote: 'URL to JSON-Feed'          
    });
});

But this does not work. I guess it's the structure/format of my JSON-Feed, right?


Solution

  • Acoording to Typehead documentation (https://github.com/twitter/typeahead.js) your JSON data is not well formated.

    It should be something like this:

    // single dataset
    $('input.typeahead-devs').typeahead({
      name: 'accounts',
      local: ['timtrueman', 'JakeHarding', 'vskarich']
    });
    

    Plus in $('document') is as to be $(document).