json object not returning value in typeahead -


i'm trying return specific data json returns nothing.

i took example http://jsfiddle.net/fresh/1hrk0qso/ works when using example url.

url: 'https://cdn.rawgit.com/twitter/typeahead.js/gh-pages/data/countries.json', 

it works when localhost

url: '../json/countries.json', 

but, when change countries.json file include multiple fields(see json below), not return anything.

json:

[ {"cities_id":"1","city":"attignat","postal_code":"01340"}, {"cities_id":"2","city":"beaupont","postal_code":"01270"}, {"cities_id":"3","city":"b\u00e9ny","postal_code":"01370"} ] 

js (modified return 'city' in replace 'name' json file):

var countries = new bloodhound({     datumtokenizer: bloodhound.tokenizers.obj.whitespace('city'),     querytokenizer: bloodhound.tokenizers.whitespace,     prefetch: {         url: '../json/json_cities.json',         filter: function (countries) {             return $.map(countries, function (city) {                 return {                     city: city                 };             });         }     } });  // initialize bloodhound suggestion engine countries.initialize();       $('.typeahead_city').typeahead(null, {         name: 'city',         displaykey: 'city',         source: countries.ttadapter()     }); 

i not understand because same example well: how list objects typeahead.js and/or bloodhound engine?

thanks lot

return following properties in second parameter of typeahead method. if want return multiple items have use display property, instead of displaykey. while customize suggestions suggestion property.

$('.typeahead_city').typeahead();

{   name: 'countries',     display: function(item){      return item.city+'–'+item.postal_code},     source: datasource.ttadapter(),     suggestion: function (data) {             return '<div>' +data.city  + '–' + data.postal_code + '</div>'}     } 

here working fiddle.

http://jsfiddle.net/geekowls/agrg3xhj/27/


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -