OpenWGA 7.10 - TMLScript reference

WGA
Object:

WGA.List([otherList])

Description

Creates a WGAList Object.

Available since version 7.10.1

A list represents a dynamic amount of single values that have a defined order and are accessible via index numbers. Lists have a dynamic size. Elements can be added, inserted and deleted from the list. Their functionality is mostly equal to JavaScript arrays. They are effectively the TMLScript representation of the Java interface java.util.List.

The index numbers of lists are zero based. The first element of the list has index number 0.

Lists can be used to create JavaScript iterators by passing them as argument to the Iterator() function.

Retrieval WGA.List()

The List object can optionally be initialised with another list object:

WGA.List(otherListObjectOrArray)

Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Inherits from object List
Properties and methods
Name Purpose
add([index, ] value) inherited Adds a value to the list
addAll([index,] list) inherited Adds all values of another list to this list
clear() inherited Removes all values  from the list
contains(value) inherited Controls if a value is contained in the list
containsAll(list) inherited Controls if this list contains all values of another list
deleteDoublets()

Removed doublets and returns the resulting list as WGAList object for further method chaining.

equals(list) inherited Tests two lists for equality
filter(function)

Calls the function with each list element and returns the filtered list as WGAList object for further method chaining.

get(idx) inherited Reads a value from the list
indexOf(value) inherited Returns the index position of a value in the list
isEmpty() inherited Controls if the list is empty
join(divider)

Creates a string from all list values (converted to string) separated with the given divider.

lastIndexOf(value) inherited Returns the (last) index position of a value in the list
map(function)

Calls the function with each list element and returns the resulting list as WGAList object for further method chaining.

remove(value)
remove(idx)
inherited
Removes a value from the list
removeAll(list) inherited Removes all values from the list that are contained in the parameter list
retainAll(list) inherited Removes all values from the list that are not contained in the parameter list
reverse()

Reverses the order of the list and returns the resulting list as WGAList object for further method chaining.

set(idx, value) inherited Sets a value at an index position
size() inherited Returns the number of values in the list
sortList([function])

Sorts the list elements according to a custom compare function.

subList(from ,to) inherited Extracts a partial list
toArray() inherited Creates a JavaScript array containing the list values
trim()

Removes null values and empty strings from the list and returns the resulting list as WGAList object for further method chaining.

Examples
WGA.List([1, 0, null, 3, 2, 1])
.trim() // [1,0,3,2,1] null removed
.deleteDoublets() // [1,0,3,2]
.sortList(function(a,b){
return a>b ? 1 : a==b ? 0 : -1
}) // [0,1,2,3] sorted
.reverse() // [3,2,1,0] reverse sorted
.map(function(v){
return "Value " + v
}) // adds string "Value" to each element

//returns [Value 3, Value 2, Value 1, Value 0]