Include reference field in repeater's itemData

I’m currently constructing a repeater that uses data from a reference field. However, the repeater’s itemData field (used in functions like forEachItem and onItemReady) does not include any reference fields, only regular data like text and numbers. I’ve seen other instances where other people have made it work (such as this past post ), but I have not been able to accomplish this myself.

Currently, I’m implementing a hacky solution in which I query the DB from within my onItemReady callback, as so:

$w('#repeater1').onItemReady(async ($item, itemData, index) => {
    // Need to perform query since references aren't part of itemData
    // signups-4 is the name of the reference field
    let result = await wixData.query("Pieces")
        .eq('_id', itemData['_id'])
        .include('signups-4').find();
    
    // More code below
    // ...
});

But I would like to see if a more elegant/efficient solution is possible.

Hi,
if I understand you correct you wish to display both data from the current collection and reference fields in a repeater. The best option to do so is described here . However, the method above uses data binding only. If you wish to do it using code, you can use the following example (see how to set repeater data from a database query here ):

import wixData from 'wix-data';

$w.onReady(function () {
  $w("#myRepeater").onItemReady( ($item, itemData, index) => {
    $item("#bookTitle").text = itemData.title;
    $item("#bookSubtitle").text = itemData.subtitle;
    $item("#bookCover").src = itemData.pic;
  } );

  wixData.query("Books")
    .include("database2")
    .find()
    .then( (results) => {
      $w("#myRepeater").data = results.items;
    } );
} );

If you need only the referenced items, you can use query referenced function instead. See here.