> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: data()

# Method package: w

# Method menu location: w --> Repeater --> data

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/$w/repeater/data.md

# Method Description:

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:

 ```javascript
 [
   {
     "_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()`](#onItemReady),
 [`onItemRemoved()`](#onItemRemoved), [`forItems()`](#forItems), and
 [`forEachItem()`](#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()`](#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()`](#forItems) and [`forEachItem()`](#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.
   1. Make changes to the objects of the data array.
   1. 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](#repeated-item-template). Then the [`onItemReady()`](#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()`](#onItemReady) event handler with the data for
      that specific item. When all of the [`onItemReady()`](#onItemReady)
      event handlers have finished running, the new items are displayed.
   1. Repeated items are removed if their IDs are no longer in the array of
      data objects. The [`onItemRemoved()`](#onItemRemoved) event handler is
      triggered for each of the removed items.
   1. 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()`](#forEachItem)
      or [`forItems()`](#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.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get a repeater's data

```javascript
let repeaterData = $w("#myRepeater").data;
```

## Set a repeater's data

```javascript
const bikeData = [
  {
    "_id":"bike1",
    "img":"wix:image://v1/6875c086ef453f5727c2b5932b3b3be4.png/Red Bike#originWidth=550&originHeight=300",
    "kind":"Red Bike"
  },
  {
    "_id":"bike2",
    "img":"wix:image://v1/703b4af24578ada6f1e11725a468096e.png/Speed Bike#originWidth=550&originHeight=300",
    "kind":"Black Bike"
  },
  {
    "_id":"bike3",
    "img":"wix:image://v1/2bb3219153c347daf475067d763be40d.png/Neon Bike#originWidth=550&originHeight=300",
    "kind":"Green Bike"
  }
];

$w("#myRepeater").data = bikeData;
```

## Modify a repeater's data

```javascript
// get current data array
let dataArray = $w("#myRepeater").data;

// change something in the data array
dataArray[0].somefield = "New value";

// reset repeater data
$w("#myRepeater").data = dataArray;
```

## Populate a repeater using data from a collection

```javascript
import wixData from 'wix-data';

$w.onReady(async function () {
  // Define how to set up each new repeater item
  $w('#helloRepeater').forEachItem( ($item, itemData, index) => {
    $item('#languageText').text = itemData.language;
    $item('#helloText').text = itemData.greeting;
    $item('#indexText').text = (index + 1).toString();

    $item('#itemContainer').onMouseIn( () => {
      $item('#languageText').show();
    });

    $item('#itemContainer').onMouseOut( () => {
      $item('#languageText').hide();
    });
  } );

  // Get data from a database collection
  const {items: collectionData} = await wixData.query('Greetings').find();
  console.log(collectionData);

  // Set the data to associate with the repeater
  $w('#helloRepeater').data = collectionData;
});

```

## Populate a repeater using static data

```javascript
// Static array of objects, each containing a unique `_id` value
const staticData = [
  {_id: '1', language: 'English', greeting: 'Hello World!'},
  {_id: '2', language: 'French', greeting: 'Bonjour monde!'},
  {_id: '3', language: 'Japanese', greeting: 'こんにちは世界！'},
  {_id: '4', language: 'Portuguese', greeting: 'Olá Mundo!'},
  {_id: '5', language: 'Spanish', greeting: '¡Hola Mundo!'},
  {_id: '6', language: 'Ukrainian', greeting: 'Привіт Світ!'}
];

$w.onReady(async function () {
  // Define how to set up each new repeater item
  $w('#helloRepeater').forEachItem( ($item, itemData, index) => {
    $item('#languageText').text = itemData.language;
    $item('#helloText').text = itemData.greeting;
    $item('#indexText').text = (index + 1).toString();

    $item('#itemContainer').onMouseIn( () => {
      $item('#languageText').show();
    });

    $item('#itemContainer').onMouseOut( () => {
      $item('#languageText').hide();
    });
  } );

  console.log(staticData);

  // Set the data to associate with the repeater
  $w('#helloRepeater').data = staticData;
});

```

## Populate a repeater using data from an external source

```javascript
// Static array of objects, each containing a unique `_id` value
const staticData = [
  {_id: '1', language: 'English', greeting: 'Hello World!'},
  {_id: '2', language: 'French', greeting: 'Bonjour monde!'},
  {_id: '3', language: 'Japanese', greeting: 'こんにちは世界！'},
  {_id: '4', language: 'Portuguese', greeting: 'Olá Mundo!'},
  {_id: '5', language: 'Spanish', greeting: '¡Hola Mundo!'},
  {_id: '6', language: 'Ukrainian', greeting: 'Привіт Світ!'}
];

$w.onReady(async function () {
  // Define how to set up each new repeater item
  $w('#helloRepeater').forEachItem( ($item, itemData, index) => {
    $item('#languageText').text = itemData.language;
    $item('#helloText').text = itemData.greeting;
    $item('#indexText').text = (index + 1).toString();

    $item('#itemContainer').onMouseIn( () => {
      $item('#languageText').show();
    });

    $item('#itemContainer').onMouseOut( () => {
      $item('#languageText').hide();
    });
  } );

  console.log(staticData);

  // Set the data to associate with the repeater
  $w('#helloRepeater').data = staticData;
});

```

## Set a repeater's data and add new data on a button click

```javascript
// static repeater data part 1
const bikeData1 = [
  {
    "_id":"bike1",
    "img":"wix:image://v1/6875c086ef453f5727c2b5932b3b3be4.png/Red Bike#originWidth=550&originHeight=300",
    "description":"Red Bike"
  },
  {
    "_id":"bike2",
    "img":"wix:image://v1/703b4af24578ada6f1e11725a468096e.png/Speed Bike#originWidth=550&originHeight=300",
    "description":"Black Bike"
  }
];

// static repeater data part 2
const bikeData2 = [
  {
    "_id":"bike3",
    "img":"wix:image://v1/2bb3219153c347daf475067d763be40d.png/Neon Bike#originWidth=550&originHeight=300",
    "description":"Green Bike"
  }
];

$w.onReady(function () {
  // handle creation of new repeated items
  $w("#myRepeater").onItemReady( ($item, itemData, index) => {
    $item("#image1").src = itemData.img;
    $item("#text1").text = itemData.description;

    $item("#image1").onClick( (event) => {
      $item("#text1").text = "Selected";
    } );
  } );

  // set the repeater data to be the first part of the static data,
  // triggering the creation of new items
  $w("#myRepeater").data = bikeData1;

  // add a handler for the "add" button that resets the repeater data
  // to be both parts of the static data, triggering the creation of
  // a new item
  $w("#addButton").onClick( () => {
    let tempData = $w("#myRepeater").data;
    $w("#myRepeater").data = tempData.concat(bikeData2);
  } );
} );

```

## Set the a repeater's data and remove some data on a button click

```javascript
// static repeater data
const bikeData = [
  {
    "_id":"bike1",
    "img":"wix:image://v1/6875c086ef453f5727c2b5932b3b3be4.png/Red Bike#originWidth=550&originHeight=300",
    "description":"Red Bike"
  },
  {
    "_id":"bike2",
    "img":"wix:image://v1/703b4af24578ada6f1e11725a468096e.png/Speed Bike#originWidth=550&originHeight=300",
    "description":"Black Bike"
  },
  {
    "_id":"bike3",
    "img":"wix:image://v1/2bb3219153c347daf475067d763be40d.png/Neon Bike#originWidth=550&originHeight=300",
    "description":"Green Bike"
  }
];

$w.onReady(function () {
  // handle creation of new repeated items
  $w("#myRepeater").onItemReady( ($item, itemData, index) => {
    $item("#image1").src = itemData.img;
    $item("#text1").text = itemData.description;

    $item("#image1").onClick( (event) => {
      $item("#text1").text = "Selected";
    } );
  } );

  // handle removal of new repeated items
  $w("#myRepeater").onItemRemoved( (itemData) => {
    console.log(`Removed: ${JSON.stringify(itemData)}`);
  } );

  // set the repeater data to be the first part of the static data,
  // triggering the creation of new items
  $w("#myRepeater").data = bikeData;

  // add a handler for the "remove" button that resets the repeater data
  // with the middle object removed, triggering the removal of the middle
  // repeated item
  $w("#removeButton").onClick( () => {
    let tempData = $w("#myRepeater").data;
    tempData.splice(1,1);
    $w("#myRepeater").data = tempData;
  } );
} );

```

---