Skip to content

Instantly share code, notes, and snippets.

@wookiehangover
Created October 6, 2011 01:13
Show Gist options
  • Save wookiehangover/1266226 to your computer and use it in GitHub Desktop.
Save wookiehangover/1266226 to your computer and use it in GitHub Desktop.
var View = Backbone.View.extend({
render: function() {
var _this = this;
// this.collection is passed in on instantiation
this.collection.deferred.done(function() {
var data = _this.collection.toJSON();
// Lets just output the response into the DOM
$('pre').html( JSON.stringify( data, '', ' ' ) );
});
}
});
// Initialize the Collection - this will call Collection.fetch()
// in the initializer and sets its deferred object to
// Collection.deferred()
var myCollection = new Collection();
// Initialize the View, passing it the collection instance
var myView = new View({
collection: myCollection
});
// Call render immediately!
myView.render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment