The standard toArray() function used callback and promise object to return the results, toLiveArray() returns an object that will be filled later. This array object can be used like a promise, it implements the then() and fail() functions.
1 2 3 4 5 |
var myArray = context.Articles.toLiveArray(); myArray.then(function () { //myArray contains elements console.log(myArray.lenght); }); |
Using live arrays with paged queries
The next() and prev() operators can be used on the output of the toLiveArray(), just like on the result of the toArray().
1 2 3 4 5 6 7 |
var myArray = context.Articles.take(10).skip(20).toLiveArray(); myArray.then(function () { myArray.next(); //or myArray.prev(); myArray.then(function () { console.log(myArray); //the elements of the array has been filled with the next chunk }); }); |
Refreshing elements in live arrays
We all want to refresh our application screen in a multi-user scenario. The refresh() function helps us to reload the elements from the data source.
1 2 3 4 5 6 7 8 |
var myArray = context.Articles.take(10).skip(20).toLiveArray(); myArray.then(function () { myArray.refresh(); myArray.then(function () { console.log(myArray); //Refresh your frontend }); }); |