I am using JS Knockout for displaying Search results from the Four Square API. I have this View Model in my Javascript code
var ViewModel = function(){
var self = this;
// Foursquare API Call :
this.foursquareURL = 'https://api.foursquare.com/v2/venues/search?ll=37.8,-122.4&query=croissant&client_id=CLIENT_ID&client_secret=CLIENT_SECRET';
this.fs_ApiCall = function()
{
$.getJSON(foursquareURL, function(data){
$foursquareElem.text('Get a croissant');
var venues = data.response.venues;
self.venueList = ko.observableArray([]);
for (var i=0; i<venues.length; i++){
self.venueList.push ({
name: venues[i].name,
lat: venues[i].location.lat,
lng: venues[i].location.lng
});
}
}).error(function() {
$foursquareElem.text( "No data available" );
});
};
};
ko.applyBindings(new ViewModel());
This is how I apply the binding in the HTML doc
<div id="foursquare-venues">
<ul data-bind= "foreach:venueList">
<li id="li-name" data-bind = "text:name">
</li>
</ul>
Uncaught ReferenceError: Unable to process binding "foreach: function (){return venueList }" Message: venueList is not defined
I was not sure if I did use the right way to push the API response in an API , but the error message seems to say that the array isn’t even defined (?) I am not sure what is going wrong here.