read

Specifies the remote settings for reading data. Can be one of:

1. A string value specifying the remote URL to call for data retrieval:

var dataSource = new shield.DataSource({
    remote: {
        read: "/content/xml/movies.xml"
    }
});

2. An object literal containing remote reading settings:

var dataSource = new shield.DataSource({
    remote: {
        read: {
            url: "/content/xml/movies.xml"
        }
    }
});

Note: When providing read settings as an object literal, the same object is used in jQuery.ajax() to make an XMLHttpRequest to the remote endpoint. This means any additional settings that are required by jQuery for the successful retrieval of data can be provided inside the read object:

var dataSource = new shield.DataSource({
    remote: {
        read: {
            url: "/content/xml/movies.xml",

            //settings below required by jQuery
            contentType: "application/json",
            dataType: "json"
        }
    }
});

3. A function expression that reads data from a remote endpoint and provides the data further down the DataSource processing pipeline:

var dataSource = new shield.DataSource({
    remote: {
        read: function (params, success, error) {
            $.ajax({
                url: "/content/xml/movies.xml",
                contentType: "application/json",
                dataType: "json",
                success: success,
                error: error
            });
        }
    }
});

The function accepts the following arguments:

Argument Name Description
params An object literal containing filter, sort, skip and take parameters. These can be used to provide custom data transformation settings to the remote endpoint.
succcess (Function) A function to call when the data is successfully retireved. The data result must be passed to the callback as a first argument.
error (Function) A function to call when there's an error and data cannot be successfully retrieved. 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.