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 must be a string and 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:
[
{
"_id": "1",
"firstName": "John",
"lastName": "Doe",
"image": "http://someImageUrl/john.jpg"
},
{
"_id": "2",
"firstName": "Jane",
"lastName": "Doe",
"image": "http://someImageUrl/jane.jpg"
}
]
Repeater data is not automatically applied to the elements in the repeated
items. You choose how to use the repeater's data in the onItemReady()
,
onItemRemoved()
, forItems()
, and
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 data
array.
The callback is triggered for each new item in the data
array as described below.
Then, you might use the forItems()
and forEachItem()
functions to modify repeater elements at some point after the data
is originally set.
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.
You cannot modify the data array in-place. To add, change, or remove objects from the repeater's data array:
data
property in a variable.data
property with the modified array.When the repeater's data
property is set:
_id
value
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.onItemRemoved()
event handler is
triggered for each of the removed items.forEachItem()
or forItems()
functions.Getting the data
property returns the repeater's current data. If you
have not yet explicitly set the repeater's data
, getting the data
property returns only the IDs of the current repeated items that were
set in the Editor.