Collection
methodBaas.Collection()
The Collection class models Baas Collections. It essentially
acts as a container for holding Entity objects, while providing
additional funcitonality such as paging, and saving
@constructor
@param {string} options - configuration object
@param {function} callback
@return {callback} callback(err, data)
Baas.Collection = function(options, callback) {
if (options) {
this._client = options.client;
this._type = options.type;
this.qs = options.qs || {};
//iteration
this._list = options.list || [];
this._iterator = options.iterator || -1; //first thing we do is increment, so set to -1
//paging
this._previous = options.previous || [];
this._next = options.next || null;
this._cursor = options.cursor || null;
//restore entities if available
if (options.list) {
var count = options.list.length;
for(var i=0;i<count;i++){
//make new entity with
var entity = this._client.restoreEntity(options.list[i]);
this._list[i] = entity;
}
}
}
if (callback) {
//populate the collection
this.fetch(callback);
}
}