Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple backbone example.
mycompany.Collections.MyCollection = Backbone.Collection.extend({
model: mycompany.Models.MyModel
, url: '/rest/models'
mycompany.Models.MyModel = Backbone.Model.extend({
url: '/rest/model'
mycompany.Views.MyView = Backbone.View.extend({
initialize: function() {
// good practice but not nessary for this simple example
// create the collection
this.collection = new mycompany.Collections.MyCollection();
// when we get the data back call render
this.collection.on('reset', this.render);
// fetch the items from the server
, render: function() {
var self = this;
// loop over the models and render each one
// do your rendering
self.$el.append('<div>' + model.get('someProperty') + '</div>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment