30
loading...
This website collects cookies to deliver better user experience
event
object.import { useScope } from 'repeater-scope';
$w.onReady(() => {
$w('#repeatedButton').onClick((event) => {
const { $item, itemData, index, data } = useScope(event);
$item('#repeatedText').text = itemData.title;
});
});
data
array that corresponds to the repeated item being created.itemData
object in the data
array.// Gets the element that the event was fired on.
const targetElement = event.target;
// Gets the element's parent element.
const parentElement = event.target.parent;
// Gets the element's type.
const elementType = event.target.type;
$w.Repeater
element.let parentElement = event.target.parent;
// Check the parent element type.
// If it isn't a Repeater take the next parent of the parent element.
while (parentElement.type !== '$w.Repeater') {
parentElement = parentElement.parent;
}
const data = parentElement.data;
itemId
in the event context object. With this ID we can found the current itemData
and index
where the event was fired from.// ID of the repeater item where the event was fired from
const itemId = event.context.itemId;
// Use the Array methods to find the current itemData and index
const itemData = data.find((i) => i._id === itemId);
const index = data.findIndex((i) => i._id === itemId);
$w.at()
to get a selector function.// Gets a selector function
// which selects items from a specific repeater item
const $item = $w.at(event.context);