My app is built using backbone. I run into problems when trying to use destroy() on a model, this is the error stack I get in chrome:
Uncaught TypeError: Cannot call method 'remove' of undefined backbone-min.js:34
f.extend.remove backbone-min.js:34
g.Events.trigger backbone-min.js:9
f.extend.destroy.d backbone-min.js:14
f.extend.destroy backbone-min.js:14
Backbone.Model.extend.remove ticketModel.js:21
Backbone.View.extend.deleteTicket ticketListView.js:44
b.each.b.forEach underscore-min.js:11
Backbone.View.extend.deleteTicketTickets ticketListView.js:49
f.event.dispatch jquery-1.7.2.min.js:3
f.event.add.h.handle.i
Any idea what this could be?
The code causing the error was literally just:
model.destroy();
model does certainly contain a model as a console.log(model) logs the object to the console as it should.
Here’s the model definition:
define([
'apiEndpoint'
],function(apiEndpoint) {
var TicketModel = Backbone.Model.extend({
url: apiEndpoint.url,
isTicket : function(){
return ( this.type === 'ticket') ? true : false;
},
isTask : function(){
return ( this.type === 'task') ? true : false;
},
//Tells you if the view is selected for bulk actions
defaults : {
isSelected: false
},
remove : function(){
this.destroy({success: function(){
console.log('success');
}});
}
});
return TicketModel;
});
In your view Why are you calling
model.destroy();? I think that you must callmodel.remove();because is your custom method to destroy.Looks like in your View you are calling
model.destroy()and latermodel.remove, but because you already destroyed your model, now you are trying to call a remove method of undefined object.