I'm having troubles getting typeahead.js to return/render all my results on my page. Here is my code:
var places = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/place/?country={{ country.id }}&name=%QUERY'
, transform: function (data) {
return data.response;
}
, wildcard: '%QUERY'
}
});
var selected = false;
$('.typeahead-place').typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'places',
displayKey: function (obj) {
if (obj.url != null && obj.url.length && (obj.street == null || obj.street.length == 0)) {
return obj.name + " (Online store)";
}
return obj.name + " (" + obj.street + ", " + obj.city + ", " + obj.postcode + ")";
},
source: places
});
Example query of Punn
gives me back the JSON from the server as:
{
"response": [
{
"id": "4",
"name": "Punnitse ja Säästä 2",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "12",
"name": "Punnitse ja Säästä 3",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "13",
"name": "Punnitse ja Säästä 4",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
},
{
"id": "9",
"name": "Punnitse ja Säästä Kamppi",
"street": "Simonkenttä, Simonkatu 9",
"city": "Helsinki",
"postcode": "00100",
"url": "http://www.punnitse.fi/"
}
]
}
Right now this renders as so: