I am working on a project that requires to typeahead textbox when some data is inputted and the data will be fetched from a webservice using query string.
I only want to show the Name, StateCode, ZipCode and ZipCodeType, Currently it's not working.
This is the code I wrote with sample JSON string
<script>
$.typeahead({
input: '.js-typeahead-city',
order: "desc",
source: {
data: [
{
"Value":"Boston, KY 40107 - Standard",
"Name":"Boston",
"Type":"Prefered",
"ZipCode":"40107",
"ZipCodeType":"Standard",
"StateCode":"KY",
"StateName":"Kentucky",
"StateFIPS":"21",
"CountryCode":"US",
"ContryName":null,
"Latitude":37.753515,
"Longitude":-85.637791,
"Country":"Nelson"
"ContryFIPS":"21179"
"TimeZone":"Eastern",
"GMT":-5,
"AreaCode":"502"
},
{
"Value":"Boston, MA 02111 - Standard",
"Name":"Boston",
"Type":"Prefered",
"ZipCode":"02111",
"ZipCodeType":"Standard",
"StateCode":"MA",
"StateName":"Massachusetts",
"StateFIPS":"25",
"CountryCode":"US",
"ContryName":null,
"Latitude":42.351267,
"Longitude":-71.064699,
"Country":"Suffolk"
"ContryFIPS":"25025"
"TimeZone":"Eastern",
"GMT":-5,
"AreaCode":"617"
},
]
},
callback: {
onInit: function (node) {
console.log('Typeahead Initiated on ' + node.selector);
}
}
});
</script>
Use the
displayconfiguration property to determine which properties of each item are used to find matches and return display results: