Created
March 13, 2012 15:21
-
-
Save codeschool-courses/2029381 to your computer and use it in GitHub Desktop.
Challenge 7-6
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 Appointment = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
'date': new Date(), | |
'cancelled': false, | |
'title': 'Checkup' | |
} | |
} | |
}); | |
var AppointmentList = Backbone.Collection.extend({ | |
model: Appointment | |
}); |
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 AppointmentView = Backbone.View.extend({ | |
template: _.template('<span class="<% if(cancelled) print("cancelled") %>"><%= title %></span><a href="#">x</a>'), | |
initialize: function(){ | |
this.model.on('change', this.render, this); | |
}, | |
render: function(){ | |
this.$el.html(this.template(this.model.toJSON())); | |
return this; | |
} | |
}); | |
var AppointmentListView = Backbone.View.extend({ | |
initialize: function(){ | |
this.collection.on('add', this.addOne, this); | |
this.collection.on('reset', this.render, this); | |
}, | |
render: function(){ | |
this.collection.forEach(this.addOne, this); | |
}, | |
addOne: function(model){ | |
var appointmentView = new AppointmentView({model: model}); | |
appointmentView.render(); | |
this.$el.append(appointmentView.el); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shouldn't the collection also have an url?