Last active
December 18, 2015 22:39
-
-
Save sagar-ganatra/5856377 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
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