Callback functions are a standard technique in JavaScript for handling events and asynchronous operations. Remote Objects uses this pattern to handle the response of its asynchronous operations. When you invoke a Remote Objects operation, you provide the parameters of the operation and, optionally, a callback function. Your JavaScript code continues uninterrupted after you invoke the operation. When the remote operation is completed and results are returned, your callback function is invoked and receives the results of the operation.
Name | Type | Description |
---|---|---|
error | JavaScript Error object | A standard JavaScript Error object. If the operation succeeded, error is null. Use error.message to retrieve the reason for a failure. |
results | JavaScript array | An array that contains the results of the operation. If the operation was a retrieve(), the results are instances of the appropriate Remote Objects. Otherwise, the array contains strings that represent the Ids of affected records. |
event | JavaScript object | A JavaScript object that provides the details of the JavaScript remoting event transporting the Remote Objects operation. |
function getAllContacts() { $j.mobile.showPageLoadingMsg(); var c = new RemoteObjectModel.Contact(); c.retrieve({ limit: 100 }, function (err, records) { // Handle errors if (err) { displayError(err); } else { // Add the results to the page var list = $j(Config.Selectors.list).empty(); $j.each(records, function() { var newLink = $j('<a>'+this.get('FirstName')+' '+this.get('LastName')+'</a>'); newLink.appendTo(list).wrap('<li></li>'); }); $j.mobile.hidePageLoadingMsg(); list.listview('refresh'); } }); }