Hello!
I was creating a comment function on a normal page to let people comment on things. I was wondering if it would be possible to create this for a dynamic page. I tried the wix example website. The only problem there is that example was for the wix blog. I tried recoding it but I didn’t get fare.
I got an error message
I got the error message ‘getPhoto’ does not exist on ‘#dynamicDataset’. The getPhoto was getPost in the example but as I am not using the blog for this I can’t use it. I looked up getBlog in wix documentation. I found it. It was only for the blog. Is there an alternative for getPost for databases?
~Thank you!~
Arthur
$w("#dynamicDataset").getPhoto().then(item => {
currentPhoto = item
loadItemComments()
})
I found it out my self! So silly of me. I forgot about the getCurrentItem. The only problem here is that the comments show on all pages of my dynamic pages. Could someone point out what I need to add?
My code:
import wixData from 'wix-data';
let currentPhoto
$w.onReady(function () {
$w("#dynamicDataset").getCurrentItem().then(item => {
currentPhoto = item
loadItemComments()
})
})
async function loadItemComments() {
const { items: itemComments } = await wixData.query("coment")
.eq("item", currentPhoto._id)
.find()
$w("#repeater1").data = itemComments
}
export function repeater1_itemReady($item, itemData, index) {
$item("#text72").text = itemData.userName
$item("#text71").text = itemData.userComment
$item("#text73").text = itemData._createdDate.toLocalDataString('en-US')
}
export function button56_click(event) {
$w("#text74").hide()
const newComment = {
item: currentPhoto._id,
userName: $w("#input1").value,
comment: $w("#input2").value
}
wixData.insert("coment", newComment).then(() => {
$w("#text74").show()
loadItemComments()
$w("#input1").value = ""
$w("#input2").value = ""
})
}
~Thank you~
Arthur