Delete records by calling del() on a Remote Objects model instance.
del() accepts two arguments,
both optional, and can delete one or many records, depending on the
arguments that you provide.
RemoteObjectModel.del([record_ids], callback_function)
record_ids is an array
of strings, where the strings are the
Ids of records to be deleted. If this parameter is omitted,
the
Id that is set on the
Remote Object instance is used. The simplest way to delete a record
is to call
del() on itself.
ctDetails = {FirstName: "Tobe", LastName: "Ornottobe"};
ct = new RemoteObjectModel.Contact(ctDetails);
ct.create();
ct.del();
More often, you might need to delete a record in response to a
button click. Deleting the record is as simple as getting the record’s
Id from the page and then passing
the
Id to
del(). For example:
var id = $jQuery('#contactId').val();
var ct = new RemoteObjectModel.Contact();
ct.del(id);
Robust code includes a callback to handle errors. The following
code accomplishes the same as the previous sample, altered to use
an event handler and a callback function.
function deleteContact(e){
e.preventDefault();
var ct = new RemoteObjectModel.Contact();
ct.del($jQuery('#contactId').val(), updateCallback);
}
function updateCallback(err, ids){
if (err) {
displayError(err);
} else {
getAllContacts();
$jQuery.mobile.changePage('#listpage', {changeHash: true});
}
}
To delete multiple records in one request—for example, checked
items from a list—pass an array of
Ids to
del().
var ct = new RemoteObjectModel.Contact();
ct.del(['003xxxxxxxxxxxxxxx', '003xxxxxxxxxxxxxxx'], function(err, ids) {
if (err) {
displayError(err);
} else {
getAllContacts();
$jQuery('#status').html(ids.length + ' record(s) deleted.');
$jQuery.mobile.changePage('#listpage', {changeHash: true});
}
});