forEach
A for each expression.
The element for an array looks like this:
{
"element": {}, // the element
"index": 0, // the index of the element. 0 based
"count": 5, // the list size
}
The element for an object like this:
{
"element": {}, // the element
"key": "theKey", // the key of the element.
}
Field Configurations
Key | Type | Description | Default Value |
---|---|---|---|
"params" (required) | Object | undefined | null |
Parameters
Key | Type | Description | Default Value |
---|---|---|---|
"actions" (required) | Array | List of actions to be execute on each element. | null |
"async" | Boolean | Specifies whether the action should perform asynchronously. | null |
"leadingDelimiter" | String | Leading delimiter for templates inside the action list. | null |
"path" (required) | String | The path to the array or object which should be iterated. | null |
"trailingDelimiter" | String | Leading delimiter for templates inside the action list. | null |
Inherited
From Base Action
Base Action
Field Configurations
Key | Type | Description | Default Value |
---|---|---|---|
"dynamicParams" | Object | Dynamic params to retrieve data from a specific context e.g. a userSetting. | null |
"leadingDelimiter" | String | The leading mustache delimiter to use. | null |
"params" | Object,Array | Object containing the properties of the action. | null |
"trailingDelimiter" | String | The trailing mustache delimiter to use. | null |
"type" | String | Type name of the action. | null |
Examples
Example 1: Iterate over an array
Goal: Show a message for each element in the array.
{
"type": "forEach",
"params": {
"path": "theList",
"leadingDelimiter": "{:",
"trailingDelimiter": ":}",
"actions": [
{
"type": "if",
"params": {
"condition": {
"mode": "equal",
"left": "{:index:}",
"right": "0"
},
"then": [
{
"type": "showMessage",
"params": {
"text": "first: {:element.text:} of {:count:}"
}
}
],
"else": [
{
"type": "showMessage",
"params": {
"text": "second: {:element.text:} of {:count:}",
"asToast": true
}
}
]
}
}
]
}
}
Example 2: Iterate over an object
Goal: Show a message for each element in the object.
{
"type": "forEach",
"params": {
"path": "theObject",
"leadingDelimiter": "{:",
"trailingDelimiter": ":}",
"actions": [
{
"type": "if",
"params": {
"condition": {
"mode": "equal",
"left": "{:key:}",
"right": "first"
},
"then": [
{
"type": "showMessage",
"params": {
"text": "first: {:element.text:} of {:key:}"
}
}
],
"else": [
{
"type": "showMessage",
"params": {
"text": "second: {:element.text:} of {:key:}",
"asToast": true
}
}
]
}
}
]
}
}