Class List
An ordered iterable collection. It optionally enforces the type of elements that may be added to the List.
An example usage:
var list = new go.List(go.Point); // make a list of Points list.add(new go.Point(0, 0)); list.add(new go.Point(20, 10)); list.add(new go.Point(10, 20)); // now list.length === 3 // and list.elt(1) instanceof go.Point
You can iterate over the items in a List:
var it = aList.iterator; while (it.next()) { window.console.log("#" + it.key + " is " + it.value); }Or:
aList.each(function(val) { window.console.log(val); });The key will range from zero to count-1.
For convenience this GoJS List class has synonyms for the following methods and property:
- get(idx): elt
- set(idx,val): setElt
- has(val): contains
- delete(val): remove
- clear(): clear
- size: count
Constructor Summary Details
Name | Description |
---|---|
List(type)
|
There are three possible constructors: List(), List(string) where string is a primitive type ('number', 'string', 'boolean', or 'function'), or List(func) where func is a class function/constructor, such as GraphObject.More... Typical usage would be something like: var list = new go.List(go.GraphObject); // keep a list of GraphObjects
|
Properties Summary Details
Name, Value Type | Description |
---|---|
count
{number}
|
This read-only property is the length of the List. |
iterator
{Iterator.
|
Gets an object that you can use for iterating over the List.More...
The key will be an integer from zero to the count-1.
The value will be the item at that index in the list.
Typical usage:
|
iteratorBackwards
{Iterator.
|
Gets an object that you can use for iterating over the List in backwards order.More...
The key will be an integer from count-1 to zero.
The value will be the item at that index in the list.
The list is not modified by traversing in reverse order.
Typical usage:
|
length
{number}
|
This read-only property is the length of the List, a synonym for the count property. |
Method Summary Details
Name, Return Type | Description |
---|---|
add(val)
|
Adds a given value to the end of the List.More... Be careful not to call this method while iterating over the collection.
|
addAll(coll)
{List.
|
Adds all of the values of a collection to the end of this List.More... Be careful not to call this method while iterating over the collection.
|
all(pred)
{boolean}
1.4
|
This is true if all invocations of the given predicate on items in the collection are true.More... Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.
|
any(pred)
{boolean}
1.4
|
This is true if any invocation of the given predicate on items in the collection is true.More... Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.
|
clear()
|
|
contains(val)
{boolean}
|
Returns whether the given value is in this List.More...
|
copy()
{List.
|
Makes a shallow copy of this List.More... The values are not copied, so if they are objects they may continue to be shared with the original List.
|
delete(val)
{boolean}
|
Removes a given value (if found) from the List.More... Be careful not to call this method while iterating over the collection.
|
each(func)
{List.
|
Call the given function on each item in the collection.More...
|
elt(i)
{T}
|
Returns the element at the given index.More...
|
first()
{T|null}
|
Returns the first item in the list, or null if there is none.
|
get(i)
{T}
|
Returns the element at the given index.More...
|
has(val)
{boolean}
|
Returns whether the given value is in this List.More...
|
indexOf(val)
{number}
|
Returns the index of the given value if it is in this List.More...
|
insertAt(i, val)
|
Insert a value before the index i.More... Be careful not to call this method while iterating over the collection.
|
last()
{T|null}
1.5
|
Returns the last item in the list, or null if these is none.
|
pop()
{T|null}
1.5
|
Returns the last item in the list and removes it from the list, or just return null if these is none.More... Use add to push an item onto the end of the list. Use last to get the last item without reducing the length of the list.
|
push(val)
|
Adds a given value to the end of the List.More... Be careful not to call this method while iterating over the collection.
|
remove(val)
{boolean}
|
Removes a given value (if found) from the List.More... Be careful not to call this method while iterating over the collection.
|
removeAt(i)
|
Removes a value at a given index from the List.More... Be careful not to call this method while iterating over the collection.
|
removeRange(from, to)
{List.
|
Removes a range of values from the List, given both the starting and the ending zero-based indexes.More...
For example, Be careful not to call this method while iterating over the collection.
|
reverse()
{List.
|
Reverse the order of items in this List.
|
set(i, val)
|
Set the element at the given index to a given value.More...
|
setElt(i, val)
|
Set the element at the given index to a given value.More...
|
sort(sortfunc)
{List.
|
Sort the List according to a comparison function.More...
|
toArray()
{Array.
|
Produces a JavaScript Array from the contents of this List.
|
toSet()
{Set.
|