I am trying create a favourite button on a repeater which, when clicked, inserts a reference of the current user into the dataset for the repeated item. I need to set the onClick for the button to return the _id vaule of the repeated item and send it into my insertReference function. I have the following:
$w.onReady(async function () {
let user = wixUsers.currentUser
let userid = user.id
let result = await wixData.query("SubmittedProjects")
.eq("approved", "Approved")
.descending("approvedDate")
.not(
wixData.query("SubmittedProjects")
.eq("size", "test")
)
.find()
await connectRepeater1(result.items)
await connectRepeater2(result.items)
$w("#favourite").onClick((event) => {
const data = $w("#repeater").data;
let clickedItemData = data.filter(item => item._id === event.context.itemId)
console.log(clickedItemData)
let clickedItemID = clickedItemData._id
console.log("user " + userid)
console.log(clickedItemID)
favourite(clickedItemID, userid)
})
})
The issue I am having is that clickedItemID seems to be returning undefined. Can anyone help identify what is going wrong here?