Search.../

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 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.

Syntax

function forItems(itemIds: Array<string>, callback: ForItemCallback): void
callback: function ForItemCallback($item: $w, itemData: Object, index: number): void

forItems Parameters

NAME
TYPE
DESCRIPTION
itemIds
Array<string>

The IDs of the items on which to run the callback function.

callback

The name of the function to run for each repeated item.

Returns

This function does not return anything.

Return Type:

void

ForItemCallback Parameters

NAME
TYPE
DESCRIPTION
$item

A selector function with repeated item scope.

itemData
Object

The object from the repeater's data array that corresponds to the current repeated item.

index
number

The index of the itemData object in the data array.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Loop through some of a repeater's repeated items

Copy Code
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} ) ;
Update data in some of a repeater's repeated items

Copy Code
1$w("#myRepeater").forItems( ["item1", "item4"], ($item, itemData, index) => {
2 $item("#repeatedImage").src = itemData.img;
3 $item("#repeatedText").text = itemData.description;
4} );