Reputation: 26558
Actually I am developing an application in backbone marionette framework. I have an simple query I searched a lot but not able to understand how to make it working. The problem is with Model.destroy()
. What I want is when I am calling Model.destroy()
first the entry has to get from server and if the response is positive then in success Call back the view should be removed.
This is my code
model.destroy({
success: function (model, response) {
},
error: function (model, response) {
}
});
But what is happening now weather it is deleted ornot from the server i.e. Which ever callback is called it will be removed from screen. So I want to remove te model from view if it goes to success callback.
Please advice.
Upvotes: 1
Views: 323
Reputation: 11003
Ideally your model really shouldn't need to know anything about its views. Instead what you should be doing is binding your view to listen to events on your model.
If you need to wait for your server to send back a response that the model has been destroyed you can pass in the{wait: true}
option when calling the destroy method.
For example, in your view's initialize method you can bind it to listen to your models destroy event,
initialize: function() {
this.listenTo(this.model, "destroy", this.destroy);
}
Upvotes: 3