Sets or gets the repeater data.
A repeater's data is stored as an array of objects. Each object in the array
must contain a unique
_id property which is used to match the object's
data to the individual repeated items of the repeater as described below.
The value of the
_id property can only contain alphanumeric
characters (A-Z, a-z, 0-9) and hyphens (
-). Other than
_id, the objects in the
repeater's data array can contain anything you want.
For example, a simple array of repeater data may look like this:
Repeater data is not automatically applied to the elements in the repeated
items. You choose how to use the repeater's data in the
forEachItem() callback functions. Most often, you
apply the data of a repeated item to the properties and functions
of the repeated elements contained in that repeated item.
Typically, you use the
onItemReady() function to set a callback
that populates the repeater's elements with the item data from the
The callback is triggered for each new item in the
data array as described below.
Then, you might use the
functions to modify repeater elements at some point after the
data is originally set.
Because setting a repeater's
data property triggers the
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
You cannot modify the data array in-place. To add, change, or remove objects from the repeater's data array:
- Store the value of the
dataproperty in a variable.
- Make changes to the objects of the data array.
- Reset the
dataproperty with the modified array.
When the repeater's
data property is set:
- New repeated items are created for each object that has an
_idvalue that is not already present in the current array of data objects. The elements in the new items are first populated with the data of the repeater's item template. Then the
onItemReady()event handler is triggered for each of the new items. Usually, you overwrite some or all of the data populated from the item template in the
onItemReady()event handler with the data for that specific item. When all of the
onItemReady()event handlers have finished running, the new items are displayed.
- Repeated items are removed if their IDs are no longer in the array of
data objects. The
onItemRemoved()event handler is triggered for each of the removed items.
- Nothing occurs to repeated items whose IDs were already in the array
of data objects, even if other data in the object has changed. To update
repeated items with the new data, use the
data property returns the repeater's current data. If you
have not yet explicitly set the repeater's
data, getting the
property returns only the IDs of the current repeated items that were
set in the Editor.
Was this helpful?