I'm trying to use a custom source (remote) with typeahead.js, and having a bit of trouble getting things to work correctly. If I hard code the data, things work fine, but when I try to implement a call to a remote service, that call is never invoked, and thus, never retrieves the data to populate the typeahead.
Here's the code:
var places = function(query, cb){
$.getJSON({
url: "https://api.foursquare.com/v2/venues/search?v=20120321&intent=global&query=%QUERY&client_id="+App.fs.client_id+"&client_secret="+App.fs.client_secret,
success: function(results){
cb(results.response.venues);
},
error: function(){
console.log("error");
}
});
};
$("#search").typeahead({
highlight: true
},
{
name: "Places",
displayKey: "name",
source: places
}
);
If I create an object called results
and manually structure the data, and pass that to cb
, things work fine. However, with this implementation, $.getJSON
is never even called. What am I missing?
Thanks!