Skip to content

Instantly share code, notes, and snippets.

@jacksonhoose
Last active August 29, 2015 14:01
Show Gist options
  • Save jacksonhoose/7dff42ae15a08a9caeee to your computer and use it in GitHub Desktop.
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
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
@blainsmith
Copy link

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 your render() function so you can chain like dataView.render().$el to get the rendered element.

PS
My uncle lives in Northampton, MA... small world ha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment