Created
May 20, 2013 00:10
-
-
Save marti1125/5609661 to your computer and use it in GitHub Desktop.
Backbone 05 codeschool collection
This file contains hidden or 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 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