Reputation: 8972
I have very simple backbone model and collection. I have a corresponding backbone.marionette.CollectionView and backbone.marionette.ItemView and they live in a backbone.marionette.region.
The ItemView template contains a "remove" button. The click event of the remove button issues a model.destroy(). A HTTP DELETE is issued to the backend, but it appears to be issued twice and because the second time it fails, the item is not removed from the collection.
Everything else is working fine, just the HTTP DELETE being issued twice. Any idea why?
I'm using Backbone.Marionette version v0.4.5
# Model:
class User extends Backbone.Model
idAttribute: "_id"
# Collection
class Users extends Backbone.Collection
model: app.User
url: "/someUrl/Users"
# CollectionView
class UserListView extends Backbone.Marionette.CollectionView
tagName: "ul",
itemView: app.UserItemView
# ItemView
class UserItemView extends Backbone.Marionette.ItemView
template: "#item"
tagName: "li"
events:
"click .edit": "edit"
"click .remove": "remove"
remove: ->
@model.destroy()
edit: (e) ->
alert JSON.stringify @model
Upvotes: 3
Views: 3945
Reputation: 3125
mhmm.... it really seems something related to some built in event or method.
Try to use non standard names for events and methods.
For instance you could try to rename the remove method in 'myRename' (remove is a pre-defined backbone method in views and collections).
like this:
# ItemView
class UserItemView extends Backbone.Marionette.ItemView
template: "#item"
tagName: "li"
events:
"click .edit": "edit"
"click .remove": "myRemove"
myRemove: ->
@model.destroy()
edit: (e) ->
alert JSON.stringify @model
hope this helps
Upvotes: 5