new Collection(dataopt)
Base collection implementation
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Array.<Model> |
<optional> |
[] | init model list |
- Source:
Methods
add(model)
Append the given model to the collection.
Parameters:
Name | Type | Description |
---|---|---|
model |
Model | object to add |
- Source:
Fires:
at(index) → {Model|null}
Get a model by the given index in the collection.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | model position in the list |
- Source:
Returns:
model or null if fail to find
- Type
- Model | null
clear() → {boolean}
Remove all models from the collection.
- Source:
Fires:
Returns:
operation status
- Type
- boolean
get(id) → {Model|null}
Get a model by its id.
Parameters:
Name | Type | Description |
---|---|---|
id |
String | Number | unique identifier |
- Source:
Returns:
model or null if fail to find
- Type
- Model | null
has(item) → {boolean}
Check if the given object is present in the collection.
Parameters:
Name | Type | Description |
---|---|---|
item |
Model | model to look for |
- Source:
Returns:
search status
- Type
- boolean
init(data) → {boolean}
Clear and fill the collection with the given list of models.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array.<Model> | model list |
- Source:
Fires:
Returns:
operation status
- Type
- boolean
insert(model, index)
Insert the given model to some place in the collection
Parameters:
Name | Type | Description |
---|---|---|
model |
Model | model object |
index |
number | model position in the list |
- Source:
Fires:
remove(model)
Delete the given model from the collection.
Parameters:
Name | Type | Description |
---|---|---|
model |
Model | object to remove |
- Source:
Fires:
sort(comparator)
Apply the custom sort method for all models in the collection.
Parameters:
Name | Type | Description |
---|---|---|
comparator |
function | custom callback to provide sorting algorithm |
- Source:
Fires:
Events
add
Append the given model to the collection event.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
item |
Model | new model object |
index |
number | model position in the list |
- Source:
clear
Remove all models from the collection event.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
data |
Array.<Model> | old model list |
- Source:
init
Set collection data event.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
data |
Array.<Model> | new model list |
- Source:
remove
Remove the given model from the collection event.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
item |
Model | removed model object |
index |
number | model position in the list |
- Source:
sort
Apply the custom sort method for all models in the collection event.
- Source: