I'm trying to debug this code for a parentView. The error thrown from this code is "Uncaught TypeError: Cannot read property 'attributes' of undefined". The console.log also comes back as undefined, however if I console.log the same this.model.total_fans later in the render function, it has a value. I don't know backbone well enough to debug this annoyingly and potentially miniscule error, but I feel like something the way this is setup is wrong, especially after reading posts about dealing with rendering subviews within a masterview here How to handle initializing and rendering subviews in Backbone.js?. I'm wondering what all is wrong here. Should I instantiate the subviews within the parents initialize? And should the parent be calling render and pagesetup on model changes??
initialize:function () {
var self = this;
// General model for this page
this.model = new geodemoModel();
// separate summary model
this.summaryModel = new summaryModel();
this.model.fetch();
this.summaryModel.fetch();
this.model.bind('change', this.render, this);
this.model.bind('change', this.pageSetup, this);
this.summaryModel.bind('change', this.render, this);
this.summaryModel.bind('change', this.pageSetup, this);
},
pageSetup:function () {
if (this.oneSelect == 'All' || this.oneSelect == 'lifetime_fans') {
console.log(this.model.total_fans);
var viewLifetime = new lifetimeView(this.model.total_fans.attributes.total_fans_object);
$('#lifetimeFans').html(viewLifetime.render().el);
}