Step 2 - Use ItemView
- Use ItemView in
views/contactForm.js
:-
Change
Backbone.View.extend
to 'Marionette.ItemView.extend' -
Instead of
template: _.template($('#tpl-new-contact').html()),
use just
template: '#tpl-new-contact',
-
Remove render method
-
Add
serializeData
methodserializeData: function() { return _.extend(this.model.toJSON(), { isNew: this.model.isNew() }); },
-
Use
ui
to organize UI elementsui: { nameInput: '.contact-name-input', telInput: '.contact-tel-input', emailInput: '.contact-email-input' },
this.trigger('form:submitted', { name: this.ui.nameInput.val(), tel: this.ui.telInput.val(), email: this.ui.emailInput.val() });
-
- Use ItemView in
views/contact.js
:-
Change
Backbone.View.extend
to 'Marionette.ItemView.extend' -
Instead of
template: _.template($('#tpl-contact').html()),
use just
template: '#tpl-contact',
-
Remove render method
-
Check in browser
-
Instead of
initialize: function() { this.listenTo(this.model, 'remove', this.remove); },
use
modelEvents
modelEvents: { 'remove': 'close' },
-