data


dataArray<object>

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:

  1. Store the value of the data property in a variable.
  2. Make changes to the objects of the data array.
  3. Reset the data property with the modified array.

When the repeater's data property is set:

  1. New repeated items are created for each object that has an _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.
  2. 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.
  3. 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 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.

Did this help?