can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
41 lines (34 loc) • 1.17 kB
Markdown
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 can.Model as it was just prior to destruction.
{function} [error] A callback to call when an error occurs. The callback receives the
XmlHttpRequest object.
{can.Deferred} A Deferred 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 = can.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();
})
```
can.