Created
November 11, 2014 21:05
-
-
Save jmcelroy5/b20b2a52ce7bf11af1bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In my javascript... | |
$.get('/get_all_bikes', function(data){ | |
// All these print statements are all what I expect... | |
console.log("response from server:", data); | |
console.log("First item:", data['response'][0]); | |
console.log("Latitude is:", data['response'][0].latitude); | |
// But for loop is not running | |
for (var i = 0; i < data.length; i++){ | |
console.log("we're in the loop!"); | |
// Current listing | |
var listing = data['response'][i]; | |
// Add marker with photo and listing data | |
L.mapbox.featureLayer({ | |
type: 'Feature', | |
geometry: { | |
type: 'Point', | |
coordinates: [listing.longitude, listing.latitude] | |
}, | |
properties: { | |
title: 'Listing title will go here', | |
description: 'Image will go here', | |
'marker-size': 'medium', | |
'marker-color': '#FF6699', | |
'marker-symbol': 'bicycle' | |
} | |
}).addTo(map); | |
} | |
}); | |
On the server-side: | |
@app.route("/get_all_bikes") | |
def get_all_bikes(): | |
# Get all active listings from db | |
all_listings = model.session.query(model.Listing).filter_by(post_status="Active").all() | |
response = [] | |
# Building final response object | |
for listing in all_listings: | |
response.append({'latitude': listing.latitude, | |
'longitude': listing.longitude, | |
'photo': listing.bike.photo, | |
'price': listing.asking_price, | |
'title': listing.bike.title}) | |
return jsonify(response=response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment