update

Specifies the remote settings for handling data items' updates. Can be one of:

1. A string containing the URL to send the data to:

var dataSource = new shield.DataSource({
    remote: {
        modify {
            update: "/update.php"
        }
    }
});

This will cause the DataSource to send the data items being updated to the specified URL using a POST request. The data being sent is a dictionary and the item(s) can be found in the list under the "edited" key in that dictionary:

{
    "edited": [{...}, {...}, ...]
}

Note: As the DataSource contains multiple/batch editing operations, the data dictionary can also contain lists with items being created and deleted under the "added" and "removed" keys.

2. An object literal containing various specific settings:

var dataSource = new shield.DataSource({
    remote: {
        modify {
            update: {
                data: function(items) {
                    return JSON.stringify(items[0].data);
                },
                url: "/books", 
                type: "PUT",
                contentType: "application/json"
            }
        }
    }
});

The data setting can optionally be used used to provide a transformation function that the DataSource can use before sending the data. The rest of the parameters are jQuery.ajax() specific parameters and can be used to configure the XMLHttpRequest object used for sending the data to the server, like the request type, headers, and other properties.

3. A function expression that sends the updated items to a remote endpoint:

var dataSource = new shield.DataSource({
    remote: {
        modify {
            update: function(items, success, error) {
                $.ajax({
                    type: "PUT",
                    url: "/book/" + items[0].data.id,
                    contentType: "application/json",
                    data: JSON.stringify(items[0].data)
                }).then(success, error);
            }
        }
    }
});

The function accepts the following arguments:

Argument Name Description
items A list of Model instances, each of which repsents an individual data item. The actual data can be accessed via its data property and it will be in the format defined by the DataSource's schema.
succcess (Function) A function to call when the data is successfully saved.
error (Function) A function to call when there's an error saving the data. An Error string or object must be provided as a first argument. See the error event for more information how this error can be handled in a uniform way.