I am using a Router for my navigation and layout management (is that right!?) and seem to have a hit a problem:
backboneQuote.Routers.ApplicationRouter = Backbone.Router.extend({
routes: {
"" : "home",
"edit/:id": "quoteEdit"
},
initialize: function(){
this.headerView = new backboneQuote.Views.headerView();
$('.header').html(this.headerView.render().el);
if(!this.itemsView){
this.items = new backboneQuote.Collections.ApplicationCollection([
{id: 1, name: "item 1"},
{id: 2, name: "item 2"},
{id: 3, name: "item 3"}
]);
this.itemsView = new backboneQuote.Views.itemsView({collection: this.items});
}
this.content = $('.container');
},
home: function(){
this.content.html(this.itemsView.render());
},
quoteEdit: function(id){
this.editQuoteView = new backboneQuote.Views.editQuoteView({model: this.items.where({id: parseInt(id, 10)})});
$('#editQuote').html(this.editQuoteView.render().el);
this.content.html($('#editQuote').html());
}
});
My itemsView render stuff:
renderItem: function(model){
var itemView = new backboneQuote.Views.itemView({model: model});
itemView.render();
$(this.el).append(itemView.el);
return this;
},
render: function(){
this.collection.each(this.renderItem);
},
I click an element which navigates the app back to the "home" function (the click event is firing fine), but the content of "this.itemsView" never seem to get put back into "this.content" div. Can anyone spot anything wrong here?
As another massive help, if anyone could provide any overall BackboneJS wisdom on anything they see here then that would be a massive help.
renderdoes not return html. You need to call the.elproperty on it, the way you have done inqouteEdit. I am assuming this was a typo in the question and not in the code. - Amith Georgethis.itemsView.render()is returning undefined? Could you verify if therenderfunction in itemsView has thereturn this;at the end of it? - Amith George