can-model
Version:
41 lines (34 loc) • 1.15 kB
Markdown
can-model.prototype.destroy destroy
can-model.prototype
Destroy a Model on the server.
`model.destroy([success[, error]])`
{function} [success] A callback to call on successful destruction. The callback receives
the Model as it was just prior to destruction.
{function} [error] A callback to call when an error occurs. The callback receives the
XmlHttpRequest object.
{Promise} A Promise that resolves to the Model as it was before destruction.
Destroys the instance by calling
[can-model.destroy] with the id of the instance.
```
recipe.destroy(success, error);
```
This triggers "destroyed" events on the instance and the
Model constructor function which can be listened to with
[can-model::bind] and [can-model.bind].
```
Recipe = Model.extend({
destroy : "DELETE /services/recipes/{id}",
findOne : "/services/recipes/{id}"
},{})
Recipe.bind("destroyed", function(){
console.log("a recipe destroyed");
});
// get a recipe
Recipe.findOne({id: 5}, function(recipe){
recipe.bind("destroyed", function(){
console.log("this recipe destroyed")
})
recipe.destroy();
})
```