onItemReady( )


Sets the function that runs when a new repeated item is created.

Use the onItemReady() function for code you want to run before new repeated items are rendered.

The onItemReady() function can be added as a static event handler using the Properties & Events Panel, or as a dynamic event handler using the $w selector.

Note: When calling this function, make sure to call it only once, and only in the page’s onReady() function.

The callback is triggered when you add new items by setting the data property or when new items are created based on a dataset that is connected to the repeater. It is not triggered for existing items that are updated when you set the data property. (For more information about when new items are created, see the data property.) To run code after updating existing items, use the forEachItem or forItems functions instead.

Because setting a repeater's data property triggers the onItemReady() callback to run, make sure you call onItemReady() before you set the data property. Failing to do so will mean that your callbacks are not triggered when you set the data property.

Usually, you use onItemReady() to:

  • 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 using a dataset to populate the contents of your repeated items, the onItemReady() callback function is triggered before the dataset populates the values of your page elements. Therefore, element values that you set using onItemReady() may be overridden when the dataset is ready. To change the values set by the dataset, use forEachItem inside the dataset's onReady(). For more information, see the forEachItem examples.

Method Declaration
Copy
Method Parameters
handlerfunctionRequired

handler($item: $w, itemData: object, index: number): void The name of the function or the function expression to run when the item is ready.

Returns
Return Type:Repeater
Was this helpful?
Yes
No