interface IHierarchicalCollection<T>
package feathers.data
extends IEventDispatcher
extended by ArrayHierarchicalCollection, TreeCollection
Interface for collections of hierarchical data, such as trees.
Events:
openfl.events.Event.CHANGE | Dispatched when the collection changes. |
---|---|
feathers.events.HierarchicalCollectionEvent.ADD_ITEM | Dispatched when an item is added to the collection. |
feathers.events.HierarchicalCollectionEvent.REMOVE_ITEM | Dispatched when an item is removed from the collection. |
feathers.events.HierarchicalCollectionEvent.REPLACE_ITEM | Dispatched when an item is replaced in the collection. |
feathers.events.HierarchicalCollectionEvent.REMOVE_ALL | Dispatched when all items are removed from the collection. |
feathers.events.HierarchicalCollectionEvent.RESET | Dispatched when the source of the collection is changed. |
feathers.events.HierarchicalCollectionEvent.UPDATE_ITEM | Dispatched
when |
feathers.events.HierarchicalCollectionEvent.UPDATE_ALL | Dispatched
when |
feathers.events.HierarchicalCollectionEvent.FILTER_CHANGE | Dispatched
when |
feathers.events.HierarchicalCollectionEvent.SORT_CHANGE | Dispatched
when |
1.0.0
.Variables
filterFunction:T ‑> Bool
A function to determine if each item in the collection should be
included or excluded from visibility through APIs like length
and
get()
.
The following example filters a collection of strings by searching for a substring at the beginning:
collection.filterFunction = (a:String) =>
{
return StringTools.startsWith(a.toLowerCase(), "john");
};
1.0.0
.See also:
sortCompareFunction:(T, T) ‑> Int
A function to compare each item in the collection to determine the order when sorted.
The return value should be -1
if the first item should appear before
the second item when the collection is sorted. The return value should
be 1
if the first item should appear after the second item when the
collection is sorted. Finally, the return value should be 0
if both
items have the same sort order.
The following example sorts a collection of Float
values:
collection.sortCompareFunction = (a:Float, b:Float) =>
{
if (a > b) {
return 1;
} else if (a < b) {
return -1;
}
return 0;
};
1.0.0
.See also:
Methods
addAt(itemToAdd:T, location:Array<Int>):Void
Adds an item to the collection at the specified location, increasing the the length of the parent branch by one.
var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
1.0.0
.See also:
contains(item:T):Bool
Determines if the collection contains the specified item.
The following example checks if a collection contains an item:
var item = { text: "New Item" };
collection.addAt(item, [0]);
var contained = collection.contains(item); // true
1.0.0
.get(location:Array<Int>):T
Returns the item at the specified location within the collection.
The following example gets an item from a specific location:
var location = [2, 0];
var item = collection.get(location);
The following example iterates over the items at the root of a collection:
for(i in 0...collection.getLength()) {
var location = [i];
var item = collection.get(i);
}
1.0.0
.getLength(?location:Array<Int>):Int
The number of items at the specified location within the collection. If called without a location, returns the length of the root.
The following example iterates over the items at the root of a collection:
for(i in 0...collection.getLength()) {
var location = [i];
var item = collection.get(location);
}
1.0.0
.isBranch(item:T):Bool
Determines if an item from the collection is a branch or not.
The following example iterates over the items at the root of a collection and prints the locations of branches to the debug console:
for(i in 0...collection.getLength()) {
var location = [i];
var item = collection.get(location);
if(collection.isBranch(item)) {
trace("branch: " + location);
}
}
1.0.0
.locationOf(item:T):Array<Int>
Returns the location of the specified item, or null
if the item is not
in the collection.
The following example gets the location of an item in the collection:
var item = { text: "New Item" };
collection.addAt(item, [0]);
var index = collection.locationOf(item); // [0]
1.0.0
.remove(item:T):Void
Removes an item from the collection.
var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.remove(item);
1.0.0
.See also:
removeAll(?location:Array<Int>):Void
Removes all items from a branch, decreasing the branch's length to zero. If called without a location, returns removes all items from the root of collection, resulting in a completely empty location.
The following example removes all items from a collection:
collection.removeAll();
1.0.0
.See also:
removeAt(location:Array<Int>):T
Removes an item from the collection at the specified location, decreasing the length of the parent branch by one.
var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.removeAt(location);
1.0.0
.See also:
set(location:Array<Int>, value:T):Void
Replaces the item at the specified location in the collection with a new item.
The following example replaces an item in a collection:
var location = [2, 0];
collection.set(location, object);
1.0.0
.See also:
updateAll():Void
Notifies components using the collection that all items should be considered changed.
The following example updates all items in the collection:
collection.updateAll();
1.0.0
.See also:
updateAt(location:Array<Int>):Void
Notifies components using the collection that an item at the specified location has changed.
The following example updates an item in the collection:
var location = [2, 0];
collection.updateAt(location);
1.0.0
.See also: