UNPKG

can-model

Version:
41 lines (34 loc) 1.15 kB
@function can-model.prototype.destroy destroy @parent can-model.prototype @description Destroy a Model on the server. @signature `model.destroy([success[, error]])` @param {function} [success] A callback to call on successful destruction. The callback receives the Model as it was just prior to destruction. @param {function} [error] A callback to call when an error occurs. The callback receives the XmlHttpRequest object. @return {Promise} A Promise that resolves to the Model as it was before destruction. @body 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(); }) ```