ParseCollection
Extends:
ParseCollection - Collections are ordered sets of models. (http://backbonejs.org/#Collection)
This implementation of Backbone.Collection provides a parse
method which coverts the response of a Parse.Query
to ParseModels. One must set a Parse.Query instance as options.query or use a getter method such as "get query()".
Please see the Collection
documentation for relevant information about the parent class / implementation.
Example:
If using Backbone-ES6 by ES6 source one can create a module for a Backbone.Collection:
import Backbone from 'backbone';
import Parse from 'parse';
export default new Backbone.Collection(null,
{
model: Backbone.Model.extend(...),
query: new Parse.Query('<TABLE_NAME>')
});
or if importing a specific model class
import Backbone from 'backbone';
import Parse from 'parse';
import Model from '<MY-BACKBONE-MODEL>'
export default new Backbone.Collection(null,
{
model: Model,
query: new Parse.Query('<TABLE_NAME>')
});
or use full ES6 style by using a getter for "model":
import Backbone from 'backbone';
import Parse from 'parse';
import Model from '<MY-BACKBONE-MODEL>'
const s_QUERY = new Parse.Query('<TABLE_NAME>');
class MyCollection extends Backbone.Collection
{
get model() { return Model; }
get query() { return s_QUERY; }
}
export default new MyCollection(); // If desired drop "new" to export the class itself and not an instance.
Constructor Summary
Public Constructor | ||
public |
constructor(models: Array<Model>, options: object) When creating a Collection, you may choose to pass in the initial array of models. |
Member Summary
Public Members | ||
public |
A comparator string indicating the attribute to sort. |
|
public |
model: Model The default Backbone.Model class to use as a prototype for this collection. |
|
public |
query: Parse.Query A Parse.Query instance |
Method Summary
Public Methods | ||
public |
clone(): Collection Returns a new instance of the collection with an identical list of models. |
|
public |
|
Public Constructors
public constructor(models: Array<Model>, options: object) source
When creating a Collection, you may choose to pass in the initial array of models. The collection's comparator may be included as an option. Passing false as the comparator option will prevent sorting. If you define an initialize function, it will be invoked when the collection is created. There are a couple of options that, if provided, are attached to the collection directly: model, comparator and query.
Pass null for models to create an empty Collection with options.
Public Members
public model: Model source
The default Backbone.Model class to use as a prototype for this collection.
Public Methods
public clone(): Collection source
Returns a new instance of the collection with an identical list of models.
Return:
Collection | Returns a new collection with shared models. |
public parse(resp: object, options: object): object | Array[] source
parse
is called by Backbone whenever a collection's models are returned by the server, in fetch. The function is
passed the raw response object, and should return the array of model attributes to be added to the collection.
This implementation depends on parseSync
which utilizes the Parse.Query attached to this collection to return
a response of Parse.Object(s) which are then parsed into ParseModels.