This is a draft of the "forEachItem-note" branch.
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 pageonReady
event fires.- The
onReady()
function has the same functionality as theonReadyAsync()
function. They differ in thatonReady()
is callback-based, whereasonReadyAsync()
is promise-based.
Syntax
function onReady(handler: ReadyHandler): voidhandler: function ReadyHandler(): void
onReady Parameters
NAME
TYPE
DESCRIPTION
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
Mixed in from:wix-dataset.Dataset
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 //onReady3 await $w("#myDataset").onReady( () => {4 let hasNextItem = $w("#myDataset").hasNext(); //true5 } );67 //onReadyAsync8 await $w("#myDataset").onReadyAsync();9 let hasNextItem = $w("#myDataset").hasNext(); //true10} );