My app contains two views with templates, router, model and collection.
root
js
collections
-collection.js
models
-model.js
routers
-router.js
templates
-add_item.html
-list.html
views
-add_item.js
-list.js
index.html
In router.js
, I'm trying to navigate to a child view.
define([
'jquery',
'backbone',
'views/item'
], function($, Backbone, ItemView) {
'use strict';
return Backbone.Router.extend({
routes: {
'': 'list',
'list/add': 'addItem',
'list/edit/:id': 'editItem'
},
addItem: function() {
new ItemView();
}
});
});
By looking at the call stack, I see that my router triggers. But the template of my child view doesn't initializes.
item.js
code:
return Backbone.View.extend({
template: _.template(itemTemplate),
events: {
'click #save': 'saveItem',
'click #cancel': 'cancel'
},
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template);
return this;
}
});