new ItemCollection(items)
Represents a collection of Items
Parameters:
| Name | Type | Description |
|---|---|---|
items |
Array.<Item> | Array.<Object> | items with which to initialize collection |
- Source:
Mixes In
Members
-
defaultOptions
-
Default options for ItemCollection instances
- Source:
Methods
-
addItem(item, options) → {Item}
-
Adds an Item to the ItemCollection. An event is emitted just before adding the Item and just after. After adding the Item the ItemCollection is re-indexed, based on the current filter function, sortBy function, and reversed flag.
Parameters:
Name Type Argument Default Description itemItem | Object item instance or options to add optionsObject <optional>
<nullable>
{} additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, the ItemCollection will not emit events noIndexboolean <optional>
<nullable>
false if true, the ItemCollection will not be re-indexed after adding the Item - Source:
Returns:
- the Item instance that was added- Type
- Item
-
addItems(items, options) → {Item[]}
-
Adds an array of items to the collection. Events and indexing will be suppressed for each individual Item added.
Parameters:
Name Type Argument Default Description itemsArray.<Item> | Array.<Object> Array of Item instances or options objects to add optionsObject <optional>
<nullable>
{} additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, no events will be emitted noIndexboolean <optional>
<nullable>
false if true, the ItemCollection will not be re-indexed - Source:
Returns:
- Array of Item instances that were added.- Type
- Item[]
-
bind() → {undefined}
-
Binds to all Item events. It's not necessary to call this directly, unless you called this.unbind at some point.
- Source:
Returns:
- Type
- undefined
-
clear(options) → {undefined}
-
Clears the collection by removing all the Items one-by-one. Events and indexing will be suppressed for each individual Item removed.
Parameters:
Name Type Argument Description optionsObject <nullable>
additional options - Source:
Returns:
- Type
- undefined
-
destroy() → {undefined}
-
Destroys the ItemCollection
- Source:
Returns:
- Type
- undefined
-
getItem(id) → {Item}
-
Gets a single item from the collection
Parameters:
Name Type Description idString Item id to find - Source:
Returns:
- Item or null if not found- Type
- Item
-
getItemEvents() → {undefined}
-
Item events to which to bind for each Item added to the collection.
- Source:
Returns:
- Type
- undefined
-
getItems(filter) → {Item[]}
-
Parameters:
Name Type Argument Description filterfunction <nullable>
the filter predicate function (takes an item and should return whether Item passes the filter) - Source:
Returns:
- Array of Items (not an ItemCollection instance)- Type
- Item[]
-
index(reason, options) → {undefined}
-
Indexes the ItemCollection based on the current filter function, sortBy function, and reversed flag. Each Item in the collection will have it's index value set based on the filter/sortBy/reversed representation of the ItemCollection items. The sorting and filtering is applied to the Items by updating the Item index values. Items are not physically moved or removed from the ItemCollection. If Items are filtered out via the filter function, the Item index will be set to -1. The Layout#getRenders method can check if item.index is -1 to decide if the Item should be displayed.
Parameters:
Name Type Argument Description reasonObject an object which indicates why the collection is being indexed optionsObject <nullable>
additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, no events will be emitted - Source:
Returns:
- Type
- undefined
-
onAnyItemEvent(e) → {undefined}
-
Parameters:
Name Type Description e- Source:
Returns:
- Type
- undefined
-
removeItem(item, options) → {undefined}
-
Removes an item from the collection
Parameters:
Name Type Argument Description itemItem item to remove optionsObject <nullable>
additional options - Source:
Returns:
- Type
- undefined
-
setFilter(filter, options) → {undefined}
-
Sets or clears the current filter function. The filter function is used to filter Items out of the ItemCollection based on a predicate. The Items are marked as filtered-out by setting the Item index to -1 (they are not actually removed from the collection, just flagged in this way).
Parameters:
Name Type Argument Default Description filterfunction <optional>
<nullable>
null the filter function (or null to clear the current filter) optionsObject <optional>
<nullable>
{} additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, events will not be emitted noIndexboolean <optional>
<nullable>
false if true, the collection will not be re-indexed with the new filter - Source:
Returns:
- Type
- undefined
-
setReversed(isReversed, options) → {undefined}
-
Reverses the sort on the collection. The reversing is applied by re-indexing all the Items in the ItemCollection.
Parameters:
Name Type Argument Default Description isReversedboolean <optional>
<nullable>
false whether the collection should be reversed. optionsObject <optional>
<nullable>
{} additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, events will not be emitted noIndexboolean <optional>
<nullable>
false if true, the collection will not be re-indexed with the new reverse value. - Source:
Returns:
- Type
- undefined
-
setSortBy(sortBy, options) → {undefined}
-
Sets or clears the current sort by function. The sort by function is used to sort the Items in the collection. The sortBy function should return a sortable value for each Item. The sort is applied by updating the Item index values.
Parameters:
Name Type Argument Default Description sortByfunction <optional>
<nullable>
null the sort by function (or null to clear the current sort) optionsObject <optional>
<nullable>
{} additional options Properties
Name Type Argument Default Description silentboolean <optional>
<nullable>
false if true, events will not be emitted noIndexboolean <optional>
<nullable>
false if true, the collection will not be re-indexed with the new sort - Source:
Returns:
- Type
- undefined
-
unbind() → {undefined}
-
Unbinds from all Item events.
- Source:
Returns:
- Type
- undefined