ListTemplate

Type class

A version of a List that has a "template".

A template is an instance of an object, that can be used to create new elements in the list without actually needing to create instances for those.

When new element is created in the list, e.g. by calling its create() method, an exact copy of the element is created (including properties and other attributes), inserted into the list and returned.

Sources

ListTemplate can be used (imported) via one of the following packages.

// ListTemplate is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Import from: "core.ts"
 * Use like: am4core.ListTemplate
 * --------------------------------------------------------
 */
import * as am4core from "@amcharts/amcharts4/core";

// ListTemplate is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Include via: <script src="core.js"></script>
 * Access items like: am4core.ListTemplate
 * --------------------------------------------------------
 */

Inheritance

ListTemplate extends List.

ListTemplate is not extended by any other symbol.

Properties

events
#

Type EventDispatcher < AMEvent < this, IListEvents < T > > >

Default new EventDispatcher()

Inherited from List

Event dispatcher.

length
#

Type number

Inherited from List

Number of items in list.

@readonly

template
#

Type T

A "template" object to copy all properties from when creating new list items.

values
#

Type Array < T >

Inherited from List

An array of values in the list.

Do not use this property to add values. Rather use dedicated methods, like push(), removeIndex(), etc.

@readonly

There are 3 inherited items currently hidden from this list.

Methods

constructor(

t: T

)

#

Returns ListTemplate

Constructor

clear()

#

Returns void

Inherited from List

Removes all items from the list.

clone()

#

Returns ListTemplate < T >

Creates an exact clone of the list, including its items and template.

contains(

value: T

)

#

Returns boolean

Inherited from List

Checks if list contains specific item reference.

copyFrom(

source: this

)

#

Returns void

Copies all elements from other list.

create(

make: object

)

#

Returns T

Instantiates a new object of the specified type, adds it to the end of the list, and returns it.

each(

f: ( value: T) => void

)

#

Returns void

Inherited from List

Calls f for each element in the list.

f should have at least one parameter defined which will get a current item, with optional second argument - index.

getIndex(

index: number

)

#

Returns T | undefined

Inherited from List

Returns an item at specified index.

hasIndex(

index: number

)

#

Returns boolean

Inherited from List

Checks if there's a value at specific index.

indexOf(

value: T

)

#

Returns number

Inherited from List

Searches the list for specific item and returns its index.

insertIndex(

index: number,
value: T

)

#

Returns void

Inherited from List

Adds an item to the list at a specific index, which pushes all the other items further down the list.

iterator()

#

Returns $iter.Iterator < T >

Inherited from List

Returns a list iterator.

moveValue(

value: T,
toIndex?: number

)

#

Returns void

Inherited from List

Moves an item to a specific index within the list.

If the index is not specified it will move the item to the end of the list.

pop()

#

Returns $type.Optional < T >

Inherited from List

Returns the last item from the list, and removes it.

push(

value: K

)

#

Returns K

Inherited from List

Adds an item to the end of the list.

pushAll(

values: Array < T >

)

#

Returns void

Inherited from List

Adds multiple items to the list.

removeIndex(

index: number

)

#

Returns T

Inherited from List

Removes a value at specific index.

removeValue(

value: T

)

#

Returns void

Inherited from List

Removes specific item from the list.

setAll(

newArray: Array < T >

)

#

Returns void

Inherited from List

Sets multiple items to the list.

All current items are removed.

setIndex(

index: number,
value: T

)

#

Returns T

Inherited from List

Sets value at specific index.

If there's already a value at the index, it is overwritten.

shift()

#

Returns $type.Optional < T >

Inherited from List

Returns the first item from the list, and removes it.

sort(

order: ( left: T, right: T) => Ordering

)

#

Returns void

Inherited from List

Reorders list items according to specific ordering function.

swap(

a: number,
b: number

)

#

Returns void

Inherited from List

Swaps indexes of two items in the list.

unshift(

value: T

)

#

Returns void

Inherited from List

Adds an item as a first item in the list.

There are 20 inherited items currently hidden from this list.

Events

#insertIndex

Param { type: "insertIndex",
  target: this }

Invoked when insertIndex method is called.

#inserted

Param { type: "inserted",
  target: this }

Invoked when item is added to the list.

@todo remove this later?

#removeIndex

Param { type: "removeIndex",
  target: this }

Invoked when item is removed.

#removed

Param { type: "removed",
  target: this }

Invoked when item is removed from the list.

@todo remove this later?

#setAll

Param { type: "setAll",
  target: this }

Invoked when setAll method is called.

#setIndex

Param { type: "setIndex",
  target: this }

Invoked when setIndex method is called.

Adapters

ListTemplate does not have any adapters.