Last active
August 29, 2015 14:01
-
-
Save jacksonhoose/7dff42ae15a08a9caeee to your computer and use it in GitHub Desktop.
Backbone View Error / /Uncaught TypeError: undefined is not a function when delegating events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
View = Backbone.View.extend({ | |
initialize: function() { | |
/*! | |
* set the collection | |
*/ | |
this.collection = new dataCollection(); | |
/*! | |
* render | |
*/ | |
this.listenToOnce(this.collection, 'sync', this.render); | |
}, | |
// always get an error when I include an events object. | |
// even if the object is empty it gets an error as soon as I add events {} | |
events: { | |
'click a.button': 'showYearsDropdown' | |
}, | |
showYearsDropdown: function(e) { | |
console.log('show years dropdown'); | |
}, | |
scrollTableLeft: function(e) { | |
console.log('scroll table left'); | |
}, | |
scrollTableRight: function(e) { | |
console.log('scroll table right'); | |
}, | |
/*! | |
* Renders the data view | |
* @return void | |
*/ | |
render: function() { | |
var template = _.template($('#template').html(), { | |
rows: this.collection.getDataFormat(), | |
years: this.collection.getYears() | |
}, { variable: 'data' }); | |
this.$el.html(template); | |
} | |
}); | |
var dataView = new View({ | |
model: model, | |
el: '.container-' + ID | |
}); | |
//Uncaught TypeError: undefined is not a function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have other code to show more context? I could try it locally.
As a side note thought make sure you always
return this;
in yourrender()
function so you can chain likedataView.render().$el
to get the rendered element.PS
My uncle lives in Northampton, MA... small world ha.