forItems( )
Runs a function for each repeated item with the given IDs.
Description
Use the forItems()
function to run a function on a specified list of
repeated items. You can use the callback function to update or pull
information from the specified repeated items.
When you set a repeater's data
property with data that changes
items with existing IDs, those changes are not automatically reflected
in the elements contained in the repeater. That is because you are
responsible for applying a repeater's data to its repeated items.
To apply the data to items with new IDs, you can use the onItemReady()
event handler.
To update items with existing IDs, you can use the forEachItem()
or
forItems()
functions.
Usually, when updating repeated items you:
Apply the repeated item's
itemData
to the properties and functions of the repeated elements contained in the repeated item being created.For example, you can use
onItemReady()
to set thesrc
property of an image in the repeater to an image source found in theitemData
object and thenshow()
the image.Add event handlers to the repeated elements contained in the repeated item being created.
For example, you can use
onItemReady()
to set theonClick()
event handler of a button in the repeater.
Syntax
function forItems(itemIds: Array<string>, callback: ForItemCallback): voidcallback: function ForItemCallback($item: $w, itemData: Object, index: number): void
forItems Parameters
NAME
TYPE
DESCRIPTION
The IDs of the items on which to run the callback function.
The name of the function or the function expression to run for each repeated item.
Returns
This function does not return anything.
Return Type:
ForItemCallback Parameters
NAME
TYPE
DESCRIPTION
The object from the repeater's data
array that corresponds to the current repeated item.
The index of the itemData
object in the data
array.
Returns
This function does not return anything.
Return Type:
Was this helpful?
1$w("#myRepeater").forItems( ["item1", "item4"], ($item, itemData, index) => {2 let repeatedElement = $item("#repeatedElement");3 let nonRepeatedElement = $item("#nonRepeatedElement");4 let itemDataValue = itemData.someProperty;5 let isEvenItem = index % 2 == 0;6} ) ;
1$w("#myRepeater").forItems( ["item1", "item4"], ($item, itemData, index) => {2 $item("#repeatedImage").src = itemData.img;3 $item("#repeatedText").text = itemData.description;4} );