I have a query/aggregate on a Table and I want to show the result in a repeater.
The table is collecting information about the use of our pages and information about what has been done on this page (view a photo, download a file,…)
The table “EventsLog” has fields “dateTime”, “context”, “element”, “process”, and the _id of course
The folowing query give me the expected result:
… datestart and datestop preparation
const dateFilter = wixData.filter().between(“dateTime”, dateStart, dateStop);
wixData.aggregate(“EventsLog”)
.limit(1000)
.filter(dateFilter)
.count()
.min(“_id”) //??? test
.group(“context”, “element”, “process”)
.ascending(“context”, “element”, “process”)
.run()
.then((results) => {
console.log(“results”);
console.log(results);
console.log(results.items[0].count);
console.log(results.items[0].process);
console.log(results.items[0].context);
console.log(results.items[0].element);
…
I have a repeater ($w(“#repeaterSummary”)) with columns.
$w("#repeaterSummary").onItemReady(($item, itemData, index) => {
console.log("repeater populate");
$item("#textDatim").text = itemData.process;
...
});
$w("#repeaterSummary").data = results.items;
This is not working. I understood that for this process to work, you need a unique id for each item, and aggregate does not give that!
I tested that with a manualy defined variable like
const items = [
{ _id: “1”, title: “Article 1” },
{ _id: “2”, title: “Article 2” },
{ _id: “3”, title: “Article 3” }
]; and it works. (if i delete the _id field, the process failed)
So my problem is to “add” a unique _id in the structure received.
I tested 2 ways:
- add a .min(“_id”) in the query definition. I receive a result with a unique id, but the name is min_id and not _id !!! so does not work!
- I tried to create a new result set, by creating a new array variable, and adding a _id field with a unique identifier, but do not know how to recreate the new resultset.
I looked at something like
let i = 0
let ItemArray =
let ItemOne =
results.items.forEach((item) => {
i++
ItemOne = [
{ _id: i, …??? }
];
ItemArray.push(ItemOne);
})
console.log(ItemArray);
What is wrong in my approach? A better way to do this?