@lucaszanotelli
I do not understand why you have such problems when placing your onClick()-function inside → onItemReady().
I use it ALWAYS without having any issues…
$w('#yourRepeaterIdhere').onItemReady(($item, itemData, index)=>{
console.log("Item-Data-I: ", itemData);
$item('#yourButtonID').onClick((event)=>{console.log(event.target)
console.log("Item-Data-II: ", itemData);
});
});
Item-Data-I: → should list all items
Item-Data-II: —> should give back just the selected item-data.
Test it and also take a look at the third implemented console-log.
The whole code for frontend-version would look like the following…
EXAMPLE: This example works with Stores/Products…
import wixData from 'wix-data';
$w.onReady(async function() {
// First getting the needed data out of Stores-DB..... ---> "productData"
let productData = await get_AllProductsData();
console.log("Product-Data: ", productData);
//Now you are ready to feed your REPEATER with the gotten DATA....
$w('#yourRepeaterIDhere').data = productData;
});
// Get all PRODUCTS-DATA------------------------------------------------------------
async function get_AllProductsData() {
// const options = {
// "suppressAuth": true,
// appOptions: {
// "includeVariants": true,
// "includeHiddenProducts": true
// }
// }
return wixData.query("Stores/Products")
//.skip(50)
.limit(100)
.find()//options
.then(async(res)=>{//console.log("RES-PRODUCTS: ", res);
if (res.items.length > 0) {console.log("Data found!");
let items = res.items; //console.log("PRODUCTS-ITEMS: ", items);
return (items);
}
else {console.log("No data found!"); return ([]);}
}).catch((err)=>{console.log(err); return [];});
}
The same one more time, but this time fired by a button-Click…
import wixData from 'wix-data';
$w.onReady(async function() {
// First getting the needed data out of Stores-DB..... ---> "productData"
$w('#myStartButtonIDhere').onClick(async()=>{
let productData = await get_AllProductsData();
console.log("Product-Data: ", productData);
//Now you are ready to feed your REPEATER with the gotten DATA....
$w('#yourRepeaterIDhere').data = productData;
});
});
// Get all PRODUCTS-DATA------------------------------------------------------------
async function get_AllProductsData() {
// const options = {
// "suppressAuth": true,
// appOptions: {
// "includeVariants": true,
// "includeHiddenProducts": true
// }
// }
return wixData.query("Stores/Products")
//.skip(50)
.limit(100)
.find()//options
.then(async(res)=>{//console.log("RES-PRODUCTS: ", res);
if (res.items.length > 0) {console.log("Data found!");
let items = res.items; //console.log("PRODUCTS-ITEMS: ", items);
return (items);
}
else {console.log("No data found!"); return ([]);}
}).catch((err)=>{console.log(err); return [];});
}
The same again, but this time our BUTTON is inside another repeater…
import wixData from 'wix-data';
$w.onReady(async function() {
// First getting the needed data out of Stores-DB..... ---> "productData"
$w('#yourRepeaterIdhere').onItemReady(($item, itemData, index)=>{
console.log("Item-Data-I: ", itemData);
$item('#yourButtonID').onClick(async(event)=>{console.log(event.target)
console.log("Item-Data-II: ", itemData);
let productData = await get_AllProductsData();
console.log("Product-Data: ", productData);
//Now you are ready to feed your REPEATER with the gotten DATA....
$w('#anotherRepeaterIDhere').data = productData;
});
});
});
// Get all PRODUCTS-DATA------------------------------------------------------------
async function get_AllProductsData() {
// const options = {
// "suppressAuth": true,
// appOptions: {
// "includeVariants": true,
// "includeHiddenProducts": true
// }
// }
return wixData.query("Stores/Products")
//.skip(50)
.limit(100)
.find()//options
.then(async(res)=>{//console.log("RES-PRODUCTS: ", res);
if (res.items.length > 0) {console.log("Data found!");
let items = res.items; //console.log("PRODUCTS-ITEMS: ", items);
return (items);
}
else {console.log("No data found!"); return ([]);}
}).catch((err)=>{console.log(err); return [];});
}
In your case, since you are working on backend, just export your query-function to backend, like you already did.