Hi,
I have done: I created a live image update preview with the repeater and trying to delete them by clicking ‘x’ icon.
The issue is: It works fine only if I exit preview mode and re-enter it. In other times, It gives error as shown below: TypeError: Cannot read property ‘_id’ of null
Please help me!! It partially works but I get the error message If I upload the image then click X.
My code is:
import wixData from 'wix-data';
function getData() {
let query = wixData.query('Images');
return query.limit(1000).find().then(results => {
console.log('getData', results);
return results.items;
})
}
$w.onReady(() => {
$w("#Imagewrite").onAfterSave(() => {
getData().then((items) => {
$w("#Imagelist").data = items;
});
});
});
export function vectorImage_click(event) {
let item = $w("#dataset1").getCurrentItem();
wixData.remove("Images", item._id)
.then(() => {
//refresh the repeater with the updated info
$w('#dataset1').refresh();
}).catch((err) => {
let errorMsg = err;
});
}
Hi Andrew,
Since you are populating the repeater via query code, you are, in effect, committing yourself to that approach, and that’s fine. But then I’m seeing that you are accessing dataset functions getCurrentItem and Refresh. After assigning the results.items to the repeater, that is what it’s tied to, not a dataset. In other words, getCurrentItem is probably not returning the current record.
Have a look at the repeater documentation introduction in the section called “Retrieve Repeater Item Data When Clicked”. That will give you a good idea how to proceed.
Thank you for the advice! I’ll try it out!
Hi! Thank you for helping me everyday! 
Above code is the code sample from the link you have given to me. It currently gives me some error, which I am trying to solve here.
Pro Gallery is not working with the Remove function since It must be removed (or deleted) before insert into database.
Thank you for the help!! It works smooth as butter!
For people, the result is shown below:
import wixData from 'wix-data';
function getData() {
let query = wixData.query('Images');
return query.limit(1000).find().then(results => {
console.log('getData', results);
return results.items;
})
}
$w.onReady(() => {
$w("#Imagewrite").onAfterSave(() => {
getData().then((items) => {
$w("#Imagelist").data = items;
});
});
});
export function vectorImage_click(event) {
let $item = $w.at(event.context);
let clickedItemData = $item("#dataset1").getCurrentItem();
wixData.remove("Images", clickedItemData._id)
.then(() => {
$w('#dataset1').refresh();
}).catch((err) => {
let errorMsg = err;
});
}