How do I get my repeater to show what my code does?

Working in
e.g. Wix Studio Editor, Wix Editor, Dev Mode, CMS, etc.

I am in the process of creating a page where I want to create a list of some players who have won the Danish Championship on Funen, but nothing happens on my page. I have tried the examples you show and they work and I intend to use the same setup, but I have spent many hours on it and it still does not work. Surely it is not because of some limitation you have?
Here is a screenshot
Og koder =”

import wixData from 'wix-data';

// import { items } from "@wix/data";

$w.onReady(function () {
  wixData.query("Import13")
    .contains("title", "DM") // viser kun poster hvor title indeholder DM
    .find()
    .then((res) => {
      console.log(">> Antal fundet poster med DM:", res.items.length);
      console.log(">> Eksempel (første post):", res.items[0]);

      const items = res.items;
      const uniqueCombos = [];
      const comboMap = {};

      items.forEach(item => {
        const key = `${item.raekke}-${item.ekPaHo}`;
        if (!comboMap[key]) {
          comboMap[key] = [];
          uniqueCombos.push({ Række: item.raekke, Type: item.ekPaHo });
        }
        comboMap[key].push(item); 
        // Samler værdier fra alle elementer i gruppen i et array.
        // Metoden push() forfiner aggregeringspipelinen for at indsamle værdier fra alle elementer i gruppen i et array.
      });

      console.log(">> Antal unikke grupper (Kombinationer):", uniqueCombos.length);
      console.log(">> Unikke kombinationer:", uniqueCombos);

      // Fyld repeater med unikke kombinationer af række + type
      $w('#repeater1').data = uniqueCombos;

      // Hvad der skal ske i hvert repeater-item
      $w('#repeater1').onItemReady(($item, itemData) => {
        console.log(">> Repeater item:", itemData);
        $item('#PBrk').text = itemData.Række || "mangler raekke";
        $item('#PBtype').text = itemData.Type || "mangler type";

        const key = `${itemData.raekke}-${itemData.ekPaHo}`;
        const players = comboMap[key] || [];

        // Indsæt spillere i tabellen
        const tableRows = players.map(p => ({
          "År": p.ar || "",
          "Navne": p.navne || "",
          "Klub": p.klub || ""
        }));

        $item('#table1').rows = tableRows;

        // Vis evt. billede fra første spiller i gruppen
        if (players.length > 0 && players[0].billede) {
          $item('#image1').src = players[0].billede;
        } else {
          $item('#image1').src = "";
        }
      });
    })
    .catch((err) => {
      console.error("Fejl ved hentning af data:", err);
    });
});

Well, first of all make sure you do provide all informations and generate a well understandable POST.

You talking here about what exactly???

I have tried the examples you show and they work and I intend to use the same setup, but I have spent many hours on it and it still does not work

And now back to your code.

Since you mentioned somekind of example you tried to follow, but you did not show those examples, let us do your setup from scratch.

Base-Coding:

a) Do you use a –> DATASET ???

b) Do you mix DATASETs + WixData ???

c) What is the name of your collection/database?

d) What is the ID of REPEATER ?

e) What is the ID of DATASET (if used one) ?

So let’s go, let us do first some clear definitions !!!

Our basic code will start with….

import wixData from ‘wix-data’;

$w.onReady(()=> {console.log('...page is ready...');
   $w(‘#myDatasetIDhere’).onReady(()=>{console.log('...dataset is ready...');
      // my code here
      // my code here
      // my code here
   });
});

But first we will do some clear definitions…

const DATASET = $w(‘#myDatasetIDhere’) –> In your example –> NO DATASET EXISTING

const REPEATER = $w(‘#repeater1’)

const DATABASE = ‘Import13’;

So now we already do have ….

import wixData from 'wix-data';

//const DATASET = $w(‘#myDatasetIDhere’) --> not existing !!!
const REPEATER = $w('#repeater1');
const DATABASE = 'Import13';


$w.onReady(async()=> {console.log('...page is ready...');
   //$w(‘#myDatasetIDhere’).onReady(()=>{ --> not existing !!!
      let myData = await getData();
      REPEATER.data = myData;
   //});
});


function getData() {
   wixData.query(“Import13”)
   .contains("title", "DM").find()
   .then((res) => {console.log('RESULTS: ', res); 
      let items = res.items; console.log('ITEMS: ', items);
      return items;
   });
}

First make sure you get this one to work!

I did not test it, so maybe you will have to modify or tweak it a little bit.

What does the code do?

It uses WixData, to get a specific data of your –> Import13 ←- collection.

It uses a RETURN-FUNCTION.

The found data return back.

And then your REPEATER do get this data.

If still not working try to modify the following part…

function getData() {
   wixData.query(“Import13”)
   .contains("title", "DM").find()
   .then((res) => {console.log('RESULTS: ', res); 
      let items = res.items; console.log('ITEMS: ', items);
      return items;
   });
}

…to…

function getData() {
   return wixData.query(“Import13”)
   .contains("title", "DM").find()
   .then((res) => {console.log('RESULTS: ', res); 
      let items = res.items; console.log('ITEMS: ', items);
      return items;
   });
}

You can expand this code a lot, but your first mission should be to get it working first.

By the way –> in this version no DATASET needed!

2 Likes

Thanks, now I got it to show the 19 groups where it says “DM”, but there should only be 12 different groups, which is also determined by Row= “row” and Type=“ekPaHo”.

Here is my codes =”import wixData from ‘wix-data’;

const DATASET=$w(‘#dataset1’);

const REPEATER=$w(“#repeater1”);

const DATABASE=“Import13”;

$w.onReady(async()=> {console.log(‘…page is ready…’);

  **let** myData = **await** getData();

  REPEATER.data = myData;

});

function getData(){

return wixData.query(“Import13”)

.contains("title", "DM")   // viser kun poster hvor title indeholder DM

.find()

.then((res) => {

 console.log(">> Antal fundet poster med DM:", res.items.length);

 console.log(">> Eksempel (første post):", res.items\[0\]);



  **let** items = res.items;



  **const** uniqueCombos = \[\];

  **const** comboMap = {};



  items.forEach(item => {

    **const** key = \`${item.raekke}-${item.ekPaHo}\`;

    **if** (!comboMap\[key\]) {

      comboMap\[key\] = \[\];

      uniqueCombos.push({ Række: item.raekke, Type: item.ekPaHo });

    }

    comboMap\[key\].push(item);  //Samler værdier fra alle elementer i gruppen i et array.

                               //Metoden push()forfiner aggregeringspipelinen for at indsamle værdier fra alle elementer i gruppen i et array.

  });

   console.log(">> Antal uniqe grupper (Kompinationer):", uniqueCombos.length);

   console.log(">> Unikke kombinationer (Kompinationer):", uniqueCombos);

   

  // Fyld repeater med unikke kombinationer af række + type

  console.log(">> Antal uniqe grupper (Kompinationer):", uniqueCombos);

  

  // Hvad der skal ske i hvert repeater-item

  $w('#repeater1').onItemReady(($item, itemData) => {

   console.log(">> Repeater item:", itemData);

   //$item('#PBrk').text = "TEST";

  $item('#PBrk').text = itemData.raekke || "mangler raekke";

  $item('#PBtype').text = itemData.ekPaHo || "mangler type";



    **const** key = \`${itemData.raekke}-${itemData.ekPaHo}\`;

    **const** players = comboMap\[key\] || \[\];



    // Indsæt spillere i tabellen

    **const** tableRows = players.map(p => ({

      "År": p.ar || "",

      "Navne": p.navne || "",

      "Klub": p.klub || ""

    }));



    $item('#table1').rows = tableRows;



    // Vis evt. billede fra første spiller i gruppen

    **if** (players.length > 0 && players\[0\].billede) {

      $item('#image1').src = players\[0\].billede;

    } **else** {

      $item('#image1').src = "";

    }

  });

 **return** items;

});

};”

Well you do not provide a lot of your setup.

Anyone knows the structure of your database.
.
.
.

Your database could look like….

col1 col2 col3 col4 col5 col6 col7
title raekke ekPaHo ar navne klub billede
DM U15 piger U15 Piger 2024 Emma Jensen Hillerød BK image://emma.jpg
DM U15 piger U15 Piger 2024 Sofie Hansen Roskilde BK image://sofie.jpg
DM U15 piger U15 Piger 2023 Laura Nielsen Odense BK image://laura.jpg
DM U15 drenge U15 Drenge 2024 Mikkel Sørensen Aalborg BK image://mikkel.jpg
DM U15 drenge U15 Drenge 2024 Lucas Pedersen Herning BK image://lucas.jpg
DM U15 drenge U15 Drenge 2023 Jonas Madsen Horsens BK image://jonas.jpg
DM U17 piger U17 Piger 2024 Clara Olsen Aarhus BK image://clara.jpg
DM U17 piger U17 Piger 2023 Amalie Lund Viborg BK image://amalie.jpg
DM U17 drenge U17 Drenge 2024 Frederik Holm Esbjerg BK image://frederik.jpg
DM U17 drenge U17 Drenge 2024 Kasper Vang Hjørring BK image://kasper.jpg
DM U19 piger U19 Piger 2024 Nanna Berg Aarhus BK image://nanna.jpg
DM U19 drenge U19 Drenge 2024 Oliver Winther Randers BK image://oliver.jpg
DM U19 drenge U19 Drenge 2023 Rasmus Krogh Vejle BK image://rasmus.jpg
DM Senior mix Senior Mix 2024 Sara Madsen Køge BK image://sara.jpg
DM Senior mix Senior Mix 2024 Oliver Nielsen Esbjerg BK image://oliver.jpg
DM Senior mix Senior Mix 2023 Lise Andersen Hørsholm BK image://lise.jpg
DM Senior damer Senior Damer 2024 Mia Bruun København BK image://mia.jpg
DM Senior herrer Senior Herrer 2024 Thomas Krog Silkeborg BK image://thomas.jpg
DM Senior herrer Senior Herrer 2023 Jens Mortensen Odense BK image://jens.jpg

Thanks, now I got it to show the 19 groups where it says “DM”, but there should only be 12 different groups, which is also determined by Row= “row” and Type=“ekPaHo”.

And all of those who will read your post (AND IS NOT A DANISH) won’t really understand your issue.

So lesson No-1: —> ALWAYS CODE IN ENGLISH !!! → CODING LANGUAGE is → ENGLISH!!!

You of course can code in your own language, but you will get problems doing this.
One of those problems is already available, since anyone do answer to your post, because not everyone will understand your issue (due to no Danish language experience)

The first confusion will arize when you are talking on some kind of → ROWS <–.
In real you are talking about → raekke
Translated into english (the language everybody understands) → taht means ROWS, and even this is still not the real word you were looking for!!!

Since you are working on a → SOCCER ← or → FOOTBAL ← table / database → the real word you were searching for is → DIVISION

So all of the following confusions is gone right now, right? …

:puzzle_piece: What You Should Decide

You have two options, depending on what “Row” actually means in your database:


:a_button_blood_type: Option A – “Row” means raekke

If “Row” = raekke, then your database already has the correct field (raekke), and you don’t need an extra one.
You just need to rename it in your visual table header so it’s clear:

title row (raekke) type (ekPaHo)
DM U15 piger U15 Piger
DM Senior mix Senior Mix

:b_button_blood_type: Option B – “Row” is a separate field

If your data actually includes a distinct row value (for example, a numeric round ID, or a league position),
then you need to add that field to your database and to your script.

**

You can follow me ?

So before someone can help you with your issue, that someone will get first totally different issues, with translations and understanding your needs and questions.

So how did your database look like one more time???

Like that…

Column 2 Column 3 Column 4 D E F G
title division type year name club image
DM U19 girls U19 Girls 2024 Nanna Berg Aarhus BK image://nanna.jpg
DM U19 boys U19 Boys 2024 Oliver Winther Randers BK image://oliver.jpg
DM U19 boys U19 Boys 2023 Rasmus Krogh Vejle BK image://rasmus.jpg
DM U17 girls U17 Girls 2024 Clara Olsen Aarhus BK image://clara.jpg
DM U17 girls U17 Girls 2023 Amalie Lund Viborg BK image://amalie.jpg
DM U17 boys U17 Boys 2024 Frederik Holm Esbjerg BK image://frederik.jpg
DM U17 boys U17 Boys 2024 Kasper Vang Hjørring BK image://kasper.jpg
DM U15 girls U15 Girls 2024 Emma Jensen Hillerød BK image://emma.jpg
DM U15 girls U15 Girls 2024 Sofie Hansen Roskilde BK image://sofie.jpg
DM U15 girls U15 Girls 2023 Laura Nielsen Odense BK image://laura.jpg
DM U15 boys U15 Boys 2024 Mikkel Sørensen Aalborg BK image://mikkel.jpg
DM U15 boys U15 Boys 2024 Lucas Pedersen Herning BK image://lucas.jpg
DM U15 boys U15 Boys 2023 Jonas Madsen Horsens BK image://jonas.jpg
DM Senior women Senior Women 2024 Mia Bruun København BK image://mia.jpg
DM Senior mix Senior Mix 2024 Sara Madsen Køge BK image://sara.jpg
DM Senior mix Senior Mix 2024 Oliver Nielsen Esbjerg BK image://oliver.jpg
DM Senior mix Senior Mix 2023 Lise Andersen Hørsholm BK image://lise.jpg
DM Senior men Senior Men 2024 Thomas Krog Silkeborg BK image://thomas.jpg
DM Senior men Senior Men 2023 Jens Mortensen Odense BK image://jens.jpg

…or something like that …???

Column 1 Column 2 Column 3 Column 4 E F G H
# title division type year name club image
7 Funen Championship U19 Girls U19 Girls 2024 Nanna Berg Aarhus BK image://nanna.jpg
8 Funen Championship U19 Boys U19 Boys 2024 Oliver Winther Randers BK image://oliver.jpg
5 Funen Championship U17 Girls U17 Girls 2024 Clara Olsen Aarhus BK image://clara.jpg
6 Funen Championship U17 Boys U17 Boys 2024 Frederik Holm Esbjerg BK image://frederik.jpg
1 Funen Championship U15 Girls U15 Girls 2024 Emma Jensen Hillerød BK image://emma.jpg
2 Funen Championship U15 Girls U15 Girls 2024 Sofie Hansen Roskilde BK image://sofie.jpg
3 Funen Championship U15 Boys U15 Boys 2024 Mikkel Sørensen Aalborg BK image://mikkel.jpg
4 Funen Championship U15 Boys U15 Boys 2024 Lucas Pedersen Herning BK image://lucas.jpg
11 Funen Championship Senior Women Senior Women 2024 Mia Bruun København BK image://mia.jpg
10 Funen Championship Senior Mix Senior Mix 2024 Oliver Nielsen Esbjerg BK image://oliver2.jpg
9 Funen Championship Senior Mix Senior Mix 2024 Sara Madsen Køge BK image://sara.jpg
12 Funen Championship Senior Men Senior Men 2024 Thomas Krog Silkeborg BK image://thomas.jpg

However at least it is now more clear and we have a first visual databse structure similar to one you have in your setup.

So now we can continue with…

what about???

:one: What hasSome() / hasAll() do

  • These only work on array fields in your database.

  • Example: if a field categories is an array like ["U15","Girls"]:

wixData.query("Players")
  .hasSome("categories", ["U15","U17"])
  .find()
  .then(res => console.log(res.items));

  • .hasSome() → returns items where at least one value matches the array.

  • .hasAll() → returns items where all values match the array.

Important: your division and type fields are strings, not arrays. So .hasSome() / .hasAll() cannot be used directly unless you store them as arrays.

…or what about…???

:two: Using .contains() or .eq() instead

Since your database fields are strings, you can filter like this:

wixData.query("Players")
  .contains("title", "Funen")  // finds records with "Funen" in title
  .eq("division", "U15")       // optional: exact match
  .eq("type", "Girls")         // optional: exact match
  .find()
  .then(res => console.log(res.items));
  • .contains() → partial match (like “DM” or “Funen”)
  • .eq() → exact match

This is exactly what most Wix repeater filtering examples use.

…and what about…???

:three: Why .hasSome() doesn’t work here

  • Your goal is to group by division + type and display unique groups.
  • Fields division and type are strings, so each player is just one value, not an array.
  • .hasSome() is for filtering array fields, not grouping or unique combinations.

YOU SURELY DID CHOOSE THE RIGHT DATABASE-STRUCTURE???

Let’s make some conclusions.
:white_check_mark: Conclusion

  • Use .contains() or .eq() for filtering string fields.
  • Use JS grouping logic (like comboMap) to create unique groups from string fields.
  • Only use .hasSome() / .hasAll() if the field in your database is an array.

And if you would not just use a pure AI solution, maybe you also would find something like —>

Equivalent Wix Aggregate Example

import wixData from 'wix-data';

wixData.aggregate("Players")
  .group("division")       // first group by division
  .group("type")           // then group by type
  .count()                 // count number of players in each group
  .run()
  .then(results => {
    // results.items contains the grouped data
    results.items.forEach(group => {
      console.log(`Division: ${group.division}, Type: ${group.type}, Count: ${group.count}`);
    });
  })
  .catch(error => {
    console.error("Aggregation Error:", error);
  });

Now, since you have a lot more informations, maybe you will now find the right way of what and how to do, to be able to solve your issue.

What you are doing right now is the beginning of the creation of an own → FILTERING-ENGINE <—

WHAT???

Filtering-Engine???

--------------------------------> Search results for 'filtering-engine' - Community Support Forum | Wix Studio

Some additional informations

:**
Now you could generate some specific (return) functions like…

function get_FunenWinners() {...}
function get_UniqueGroups() {...}

function get_…

…but wait!!! Why not directly generating something like a —> reusable generic aggregation utility for your backennd ???

By the way, you knew that on backend it should work even faster?

EXAMPLE:

import wixData from 'wix-data';

/**
 * Get grouped players by division and type
 * @param {string} titleFilter - Optional: filter players whose title contains this string
 * @returns {Promise<Array>} - Resolves to an array of groups with players
 */
export function getGroupedPlayers(titleFilter = "") {
  let aggregate = wixData.aggregate("Players");

  // Apply filter if provided
  if (titleFilter) {
    aggregate = aggregate.match(wixData.filter().contains("title", titleFilter));
  }

  // Build aggregation
  return aggregate
    .group("division")
    .group("type")
    .items(["_id", "name", "title", "division", "type"]) // include relevant fields
    .run()
    .then(results => {
      // Map results to match desired output
      return results.items.map(group => ({
        division: group.division,
        type: group.type,
        players: group.items
      }));
    });
}

Usage Example

getGroupedPlayers("Funen")
  .then(groups => {
    console.log("Grouped Players:", groups);
  })
  .catch(error => {
    console.error("Error fetching grouped players:", error);
  });

:white_check_mark: Benefits of this approach
Reusable: call getGroupedPlayers() anywhere.

Optional filter: pass a title filter if needed.

Returns exactly the same structure as your manual groupsMap.

Fully server-side aggregation → faster and more efficient.

As you can see, there are so many possibilities and you can expand your code even much much more —> making it more [ROBUST, FLEXIBLE, DYNAMIC and AUTOMATIC and even if you want → AI-DRIVEN]

But all of those mentioned possibilities can be only achieved when using pure coded Wix-Data-Solutions! As soon as you start to mix it up with Datasets → you will get troubles.

Thanks for this, it gave me a good understanding of it, so I can get further. Yes, the language thing is a problem, but you have to try to get the best out of it.
The first problem was that I didn’t include “_id” in the codes, as soon as it was included you could see what was happening in the “repeater”.

3 Likes

Yes, the id is very important, even important how the id is defined…

  1. id

  2. ID

  3. _id

I think the right one was –> _id

Repeater will not work without an included _id, that’s right!

2 Likes