четвъртък, 16 януари 2014 г.

JavaScript DataSource local data

In this blog entry, we look at the ShieldUI DataSource control, and how to bind it to local data.
To bind Shield UI DataSource to local data, provide the data initialization option when creating a new DataSource instance. The data setting must be a JavaScript array or an object containing the data in a nested property:
1
2
3
4
5
6
7
8
var ds = new shield.DataSource({
    data: [/*...*/]
});
 
ds.read().then(function () {
    var dataView = ds.view;
    //dataView contains the local data
});
Alternatively, if the local data is a JavaScript array and there are no additional initialization options, you can provide the data array directly as a first constructor argument:
1
2
3
4
5
6
var myDataArray = [/*...*/];
var ds = new shield.DataSource(myDataArray);
ds.read().then(function () {
    var dataView = ds.view;
    //...
});
Once the DataSource is initialized, the local array is accessible through the data property of the DataSource.

Няма коментари:

Публикуване на коментар