Search.../

onReady( )

Adds an event handler that runs when the dataset is ready.

Description

The onReady() function allows you to optionally perform actions right after the dataset has loaded its data from the collection and updated all connected page elements with their corresponding values.

Notes:

  • The dataset onReady event only fires after the page onReady event fires.
  • The onReady() function has the same functionality as the onReadyAsync() function. They differ in that onReady() is callback-based, whereas onReadyAsync() is promise-based.

Syntax

function onReady(handler: ReadyHandler): void
handler: function ReadyHandler(): void

onReady Parameters

NAME
TYPE
DESCRIPTION
handler

The ready handler.

Returns

This function does not return anything.

Return Type:

void

ReadyHandler Parameters

This function does not take any parameters.

Returns

This function does not return anything.

Return Type:

void

Related Content:

Was this helpful?

Register a callback to run after the dataset is ready

Copy Code
1$w("#myDataset").onReady( () => {
2 console.log("The dataset is ready");
3} );
Get whether the current item is the last item after the dataset is ready

This example demonstrates how both onReady() and onReadyAsync() functions do the same thing.

Copy Code
1$w.onReady(async () => {
2 //onReady
3 await $w("#myDataset").onReady( () => {
4 let hasNextItem = $w("#myDataset").hasNext(); //true
5 } );
6
7 //onReadyAsync
8 await $w("#myDataset").onReadyAsync();
9 let hasNextItem = $w("#myDataset").hasNext(); //true
10} );