Skip to content

Instantly share code, notes, and snippets.

@codeschool-courses
Created March 7, 2012 21:25
Show Gist options
  • Save codeschool-courses/1996339 to your computer and use it in GitHub Desktop.
Save codeschool-courses/1996339 to your computer and use it in GitHub Desktop.
Anatomy of Backbone 1-7
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});
@marka2g
Copy link

marka2g commented Mar 29, 2012

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('

  • ' + this.model.get('title') + '
  • ');
    }
    });
    var appointmentView = new AppointmentView({model: appointment});

    appointmentView.render();
    $('#app').html(appointmentView.el);

    @iamtchelo
    Copy link

    appointmentView.render();
    $('#app').html(appointmentView.el);

    It's right! =)

    @vsakaria
    Copy link

    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!

    @sushantksh
    Copy link

    I did not get the $('#app').html(appointmentView.el);
    Where does the #app come from ?
    I am beginner. :)

    @anshula
    Copy link

    anshula commented Jun 28, 2013

    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?

    @Gero1369
    Copy link

    this exercise, "Set the Title", and "View Instance" seem not to be working correctly.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment