forEachItem( )


Runs a function for each repeated item.

Use the forEachItem() function to run a function on all of a repeater's repeated items. You can use the callback function to update or pull information from all of the repeater's 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 the src property of an image in the repeater to an image source found in the itemData object and then show() the image.

  • Add event handlers to the repeated elements contained in the repeated item being created.

    For example, you can use onItemReady() to set the onClick() event handler of a button in the repeater.

Note: When a page loads, datasets load after repeaters. To use forEachItem() with repeater data populated by a dataset, make sure to call it within the dataset's onReady() function.

Method Declaration
Copy
Method Parameters
callbackfunctionRequired

callback($item: $w, itemData: object, index: number): void The name of the function to run for each repeated item.

Was this helpful?
Yes
No