Hi. Trying to assign the link of a button in repeater based on certain values from multiple referred databases.
My dataset for the repeater is set for MainProductCategories database which has 2 columns referred to 2 separate databases called teleskoptrucks and trucks.
$w.onReady(function () {
$w("#dataset1").onReady( () => {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let teleskopref = itemData.teleskoptruckReference;
let truckref = itemData.truckReference;
// let liftref = itemData.liftReference;
console.log(teleskopref);
console.log(truckref);
//console.log(liftref);
if(itemData.mainCategory === "Teleskoptruck"){
wixData.query("Teleskoptrucks")
.eq("_id", teleskopref)
.find()
.then( (results) => {
let link = results.items[0]['link-teleskoptrucks-title'];
console.log(link);
$item('#button3').link = link;
});
if(itemData.mainCategory === "Truck"){
wixData.query("Truck")
.eq("_id", truckref)
.find()
.then( (results) => {
let link = results.items[0]['link-truck-kategori'];
console.log(link);
$item('#button3').link = link;
});
}
}
else {
$item("#button3").label = "No Value Given!";
}
console.log("The dataset is ready");
} );
} );
I get the ID value from let teleskopref = itemData.teleskoptruckReference; perfectly. But for let truckref = itemData.truckReference; I get a whole array of the referred database value instead of just the ID value!
Once I get the reference IDs I would like to query the different databases based on the value of the mainproduct category in the dataset.
Console log snapshot below:
How can I firstly get just the ID instead of the whole array.
And secondly is my IF function stated correctly to change the value of the button url to separate dynamic pages accordingly.
Please do let me know if there’s any assistance I can get. Would be massive. TIA.