Skip to content

Instantly share code, notes, and snippets.

@sagar-ganatra
Last active December 18, 2015 22:39
Show Gist options
  • Save sagar-ganatra/5856377 to your computer and use it in GitHub Desktop.
Save sagar-ganatra/5856377 to your computer and use it in GitHub Desktop.
var App = {};
App.BBCollection = Backbone.Collection.extend({
initialize: function (options) {
console.log('Collection - initialize');
}
});
App.BBView = Backbone.View.extend({
initialize: function () {
console.log('View - initialize');
// Create an instance of a BBCollection
var BBCollectionInstance = new App.BBCollection();
// Call fetch on the collection instance
BBCollectionInstance.fetch({
error: this.errorHandler,
url: 'sampleData.json'
});
/*
* listen to the reset event on the collection and
* call render when the collection changes.
* However, reset is not triggered by default, the fetch
* method should pass the key 'reset' as true.
*/
this.listenTo(BBCollectionInstance, 'reset', this.render);
},
render: function (collection) {
console.log('View - render');
console.log(collection.toJSON());
},
errorHandler: function (error) {
console.log('View - errorHandler');
}
});
new App.BBView();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment