Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Created September 12, 2012 19:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewxhill/3709298 to your computer and use it in GitHub Desktop.
Save andrewxhill/3709298 to your computer and use it in GitHub Desktop.
CartoDB Backbone for data-driven webpages
// Set the CartoDB user account
var CartoDB = Backbone.CartoDB({
user: viz2
});
// Create a model, here directly from SQL
// You can also do it with simply a table name and list of columns
var parksModel = CartoDB.CartoDBCollection.extend({
sql: "SELECT name FROM nyc_parks ORDER BY ST_Area(the_geom) DESC LIMIT 10"
});
// Create a new instance of our model and fetch the records
var parks = new parksModel();
parks.fetch();
// When records are loaded, do something with them
parks.bind('reset', function() {
var parks_list = new Array();
parks_list.push(p.get('name'));
alert(parks_list);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment