-
-
Save codeschool-courses/1996339 to your computer and use it in GitHub Desktop.
var Appointment = Backbone.Model.extend({}); | |
var appointment = new Appointment(); | |
appointment.set('title', 'My knee hurts'); | |
var AppointmentView = Backbone.View.extend({ | |
render: function(){ | |
$(this.el).html('<li>' + this.model.get('title') + '</li>'); | |
} | |
}); | |
var appointmentView = new AppointmentView({model: appointment}); |
appointmentView.render();
$('#app').html(appointmentView.el);
It's right! =)
Yes the View is like a self containing object. So render just updates the View object but doesn't return anything. To access the View HTML use appointmentView.el!
Interesting Stuff!
I did not get the $('#app').html(appointmentView.el);
Where does the #app come from ?
I am beginner. :)
it's just a JQuery selector that gets an element with the id of "app" from the html file. however, since the code school course doesn't show html files, you just have to assume that this backbone script is called from an html doc that has a tag with an id of "app". this is where you nest the appointment view's element (li). was that what you were asking?
this exercise, "Set the Title", and "View Instance" seem not to be working correctly.
var Appointment = Backbone.Model.extend({});
var appointment = new Appointment();
appointment.set('title', 'My knee hurts');
var AppointmentView = Backbone.View.extend({
render: function(){
$(this.el).html('
}
});
var appointmentView = new AppointmentView({model: appointment});
appointmentView.render();
$('#app').html(appointmentView.el);