destroy

  • function
can.Model.prototype.destroy  

Destroy a Model on the server.

model.destroy([success[, error]])

Parameters

  1. success {function()}Optional

    A callback to call on successful destruction. The callback recieves the can.Model as it was just prior to destruction.

  2. error {function()}Optional

    A callback to call when an error occurs. The callback receives the XmlHttpRequest object.

Returns

{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 bind and 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();
})