Constructor
new ModelCollection(modelDefinition, values, pagerData)
- Source:
Creates a new ModelCollection
object based on the passed modelDefinition
. Additionally values can be added by passing
Model
objects in the values
parameter. The collection also exposes a pager object which can be used to navigate through
the pages in the collection. For more information see the Pager
class.
Parameters:
Name | Type | Description |
---|---|---|
modelDefinition |
ModelDefinition | The |
values |
Array.<Model> | Initial values that should be added to the collection. |
pagerData |
Object | Object with pager data. This object contains data that will be put into the |
Members
modelDefinition
- Source:
Properties:
Name | Type | Description |
---|---|---|
modelDefinition |
ModelDefinition | The |
pager
- Source:
Properties:
Name | Type | Description |
---|---|---|
pager |
Pager | Pager object that is created from the pagerData that was passed when the collection was constructed. If no pager data was present the pager will have default values. |
size
- Source:
Properties:
Name | Type | Description |
---|---|---|
size |
Number | The number of Model objects that are in the collection. |
Contains the number of Model objects that are in this collection. If the collection is a collection with a pager. This does not take into account all the items in the database. Therefore when a pager is present on the collection the size will return the items on that page. To get the total number of items consult the pager.
Methods
add(value) → {ModelCollection}
- Source:
Adds a Model instance to the collection. The model is checked if it is a correct instance of Model
and if it has
a valid id. A valid id is a uid string of 11 alphanumeric characters.
Parameters:
Name | Type | Description |
---|---|---|
value |
Model | Model instance to add to the collection. |
Throws:
-
-
When the passed value is not an instance of
Model
- Type
- Error
-
-
-
Throws error when the passed value does not have a valid id.
- Type
- Error
-
Returns:
Returns itself for chaining purposes.
- Type
- ModelCollection
clear() → {this}
- Source:
Clear the collection and remove all it's values.
Returns:
Returns itself for chaining purposes;
- Type
- this
toArray() → {Array}
- Source:
If working with the Map type object is inconvenient this method can be used to return the values of the collection as an Array object.
Returns:
Returns the values of the collection as an array.
- Type
- Array