Step 4 - Simple Contact view
-
Create file
app/js/views/contact.js
with view:ContactManager.Views.Contact = Backbone.View.extend({ render: function() { var html = '<h1>' + this.model.get('name') + '</h1>'; this.$el.html(html); return this; } });
and add to index.html:
<script src="app/js/views/contact.js"></script>
-
Show in console how to render and view's root element (el)
var bob = new ContactManager.Models.Contact({name: 'Bob'}) var bobView = new ContactManager.Views.Contact({model: bob}) bobView.render() bobView.$el
-
Append view to body:
$('body').append(bobView.$el)