Guys I have a problem:
I need to show the count results from an Aggregate code into a repeater. In the console it works fine but when I try to show the results in a repeater I have this 2 messages:
Wix code SDK Warning: The text parameter of “ciudad” that is passed to the text method cannot be set to null or undefined.
Wix code SDK error: Each item in the items array must have a member named _id
which contains a unique value identifying the item.
This is the code Im using:
export function button15_click(event) {
$w('#repeater2').forEachItem (($item, itemData) => {
$item("#ciudad").text = itemData.ciudad;
})
wixData.aggregate("HistoriaClinica")
.group("ciudad")
.count()
.run()
.then( (results) => {
let items = results.items;
$w("#repeater2").data = results.items;
console.log(items)
} );
}
Any thoughts? Thanks!
https://www.wix.com/velo/reference/$w/repeater/introduction
This is an example how a prepared REPEATER-DATA should look like.
[
{
"_id": "1",
"firstName": "John",
"lastName": "Doe",
"image": "http://someImageUrl/john.jpg"
},
{
"_id": "2",
"firstName": "Jane",
"lastName": "Doe",
"image": "http://someImageUrl/jane.jpg"
}
]
At least you will need an —> ID <— and a —> VALUE <—
[
{"_id": "001", "firstName": "John"},
{"_id": "002", "firstName": "Rebecca"},
{"_id": "003", "firstName": "Silvio"},
{"_id": "004", "firstName": "Sindy"},
{"_id": "005", "firstName": "Antonio"},
{"_id": "006", "firstName": "Stefano"},
]
Compare this DATA-STRUCTURE with —> console.log(items)
Do both have the same DATA-STRUCTURE after your AGGREGATION?
Hi! Thanks for your quick answer. This is what I get in the console:
0:
{…}
json Tabla Copy JSON
_id:
“ATLANTICO”
count:
1
ciudad:
“ATLANTICO”
I just need to put than on a repeater
Try this one…
$w.onReady(async function() {
$w('#button15').onClick(()=>{
myFunction();
})
$w("#repeater2").onItemReady(($item, itemData, index) => {
$item("#ciudad").text = itemData.ciudad;
});
});
function myFunction() {
wixData.aggregate("HistoriaClinica")
.group("ciudad")
.count()
.run()
.then((results) => {
let items = results.items; console.log(items)
$w("#repeater2").data = items;
} );
}
@russian-dima CLOSE!
I just have this error:
Wix code SDK error: Each item in the items array must have a member named _id
which contains a unique value identifying the item.
@danieltalero78
Check this little and quick EXAMPLE…
https://www.media-junkie.com/ugly-code
let xxxx =[
{"_id": "001", "firstName": "John"},
{"_id": "002", "firstName": "Rebecca"},
{"_id": "003", "firstName": "Silvio"},
{"_id": "004", "firstName": "Sindy"},
{"_id": "005", "firstName": "Antonio"},
{"_id": "006", "firstName": "Stefano"},
]
$w.onReady(async function() { console.log(xxxx)
$w("#repeater1").data = xxxx;
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#TXTname").text = itemData.firstName;
});
});
Everything works fine like expected. 
Here with ID…
let xxxx =[
{"_id": "001", "firstName": "John"},
{"_id": "002", "firstName": "Rebecca"},
{"_id": "003", "firstName": "Silvio"},
{"_id": "004", "firstName": "Sindy"},
{"_id": "005", "firstName": "Antonio"},
{"_id": "006", "firstName": "Stefano"},
]
$w.onReady(async function() { console.log(xxxx)
$w("#repeater1").data = xxxx;
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#txtID").text = itemData._id;
$item("#txtNAME").text = itemData.firstName;
});
});
Thanks again
So what I did was:
let xxxx =[
{"_id": "001", "firstName": "John"},
{"_id": "002", "firstName": "Rebecca"},
{"_id": "003", "firstName": "Silvio"},
{"_id": "004", "firstName": "Sindy"},
{"_id": "005", "firstName": "Antonio"},
{"_id": "006", "firstName": "Stefano"},
]
$w.onReady(async function() {
$w('#button15').onClick(()=>{
start_myFunction();
})
$w("#repeater2").data = xxxx;
$w("#repeater2").onItemReady(($item, itemData, index) => {
$item("#id").text = itemData._id;
$item("#ciudad").text = itemData.firstName;
});
});
function start_myFunction() {
wixData.aggregate("HistoriaClinica")
.group("ciudad")
.count()
.run()
.then((results) => {
let items = results.items; console.log(items)
$w("#repeater2").data = items;
} );
}
It works showing the xxxx values but it doesn’t show the values of the aggregate results when I click the button15

let xxxx =[
{"_id": "ATLANTICO", "firstName": String(1), "ciudad": "ATLANTICO"},
// {"_id": "002", "firstName": "Rebecca"},
// {"_id": "003", "firstName": "Silvio"},
// {"_id": "004", "firstName": "Sindy"},
// {"_id": "005", "firstName": "Antonio"},
// {"_id": "006", "firstName": "Stefano"},
]

Yes but the results of the aggregate are 52! I just show you the first one.
What I mean is: ¿Is there any way to show all of the results in the repeater?
This is the console

Thanks for your patience!
The value of the _id property can only contain alphanumeric characters (A-Z, a-z, 0-9) and hyphens (-).
This is why your DATA is NOT ACCEPTED by the REPEATER.
Take a closer look onto your —> IDs

Especialy —> "BUCARAMANGA " <— Is there a —> SPACE to be found???
Normaly you should get a error-message like…

The same with -->“BAHIA SOLANO CHOCO”–> even 3-spaces in the ID-Value😮
YOU ARE A GENIUS. Thats the problem.
Is there anyway to show the results maybe in a table?
A table uses the same DATA-STRUCTURE (as i know).
You will have to change your DATA-STRUCTURE (directly in your DB, or by creating a CONVERTER, which will first —> convert your ID-DATA, before pushing it to a —> REPEATER or TABLE).
Little hint : Convert SPACES in a STRING to —> HYPHENS! That should do the trick.
And do not forget to like it, if you really liked it 