Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created May 20, 2013 00:10
Show Gist options
  • Save marti1125/5609661 to your computer and use it in GitHub Desktop.
Save marti1125/5609661 to your computer and use it in GitHub Desktop.
Backbone 05 codeschool collection
var AppointmentList = Backbone.Collection.extend({
model: Appointment
});
////////////////////////////
var Appointment = Backbone.Model.extend({});
var AppointmentList = Backbone.Collection.extend({
model: Appointment
});
////////////////
var appointments = new AppointmentList();
var json = [
{title: 'Back pain'},
{title: 'Dry mouth'},
{title: 'Headache'}
];
appointments.reset(json);
/////////////////////////////////
var Appointment = Backbone.Model.extend({});
var AppointmentList = Backbone.Collection.extend({
model: Appointment,
url: '/appointments'
});
var appointments = new AppointmentList();
appointments.fetch();
var appointments = new AppointmentList();
appointments.on('reset', function() {
alert("fetched " + this.length + " appointments from the server");
});
appointments.fetch();
appointments.fetch({silent: true});
/////////////////////
var appointments = new AppointmentList();
appointments.on('add', function(appointment){
console.log("Dr. Goodparts added the " + appointment.get('title') + " appointment");
});
var titles = appointments.map(function(appointment){
return appointment.get('title');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment