Combining multiple database cells in 1 text field inside of a repeater

Question:
I am looking for a way to combine the content of 3 database fields in 1 text field, that is placed inside of a repeater. Elsewhere on my website I am using the code like written below, but it returns “undefined” on my website when I use this code inside a repeater.

Good to know: The fields “flightairline” and “flight_class” are both referenced database fields.

What am I doing wrong?

$w.onReady( () => {
$w(“#dayOneDataset”).onReady( () => {
let item = $w(“#dayOneDataset”).getCurrentItem();
let leg1airline = item.flightairline;
let leg1flightnumber = item.flightNumber1;
let leg1class = item.flight_class;
$w(“#text595”).text = leg1airline + “·” + leg1flightnumber + “·” + leg1class ;
} );
} );

Product:
Wix Studio Editor

Hi, @misterwanderluster !!

Hello, or good evening. For now, please replace the collection name and repeater name in the following code with the appropriate values and try running it. By the way, since I haven’t tested this code, I’m not sure if it will work.

Since I’m not sure what the structure of the returned value is, please check the log to confirm and then rewrite the code accordingly. :innocent:


import wixData from "wix-data";

$w.onReady(() => {

  wixData.query("yourCollectionName")
        .include(["flightairline", "flight_class"])
        .find()
        .then((results) => {

            console.log(results.items);

            $w("#yourRepeaterId").onItemReady(($item, itemData, index) => {
                let leg1airline = itemData.flightairline || "";
                let leg1flightnumber = itemData.flightNumber1 || "";
                let leg1class = itemData.flight_class || "";
                $item("#text595").text = `${leg1airline}·${leg1flightnumber}·${leg1class}`;
            });

            $w("#yourRepeaterId").data = results.items;

        })
        .catch((err) => {
            console.log("error:", err);
        });

});


Hi @onemoretime ,

Thanks so much for your time and efforts so far! I have replaced the collection and repeater name, but I still get some errors:

Do you have any idea what causes these errors and what I can do to fix them?

Best regards,

Stefan

Hi, @misterwanderluster !!

Please try replacing [“flightairline”, “flight_class”] with “flightairline”, “flight_class” and run it again. Also, note that “yourRepeaterId” should be your repeater’s ID, not the dataset ID. Replace “#dayOneDataset” with your repeater’s ID and try again. If it works, check the console log for console.log(results.items). :upside_down_face:

You can check out the Velo docs for examples of repeaters with code.

https://dev.wix.com/docs/velo/api-reference/$w/repeater/on-item-ready