How to remove from array in onClick inside repeater?

I have a repeater and when someone clicks a button inside the repeater I want to remove the clicked item. All items in the array have a _id field with 0,1,2,3,4,5,6 as strings.

cartArray holds all items and for some reason the click event gets triggered as many times as there are items in the array. It should trigger once and the splice would take out the correct item.

Are there any bugs in the new way of handling the repeaters?

$w("#cartRepeater").onItemReady(($item, itemData, index) => {
        const deleteButton = $item("#rowDeleteButton");
        $item("#rowItem").text = itemData.title;
        $item("#rowSum").text = itemData.sum.toString();
    
        deleteButton.onClick((event) => { 
            console.log("Item in cart clicked has index: " + index);
            cartArray.splice[index,1];
            console.log(cartArray);
        });
    });

Please someone.

Hi,
Is cartArray the array of items you pass on to the repeater?
if so, make sure to pass the array again once you finished removing the unnecessary item.

$w("#cartRepeater").data = cartArray;

This will trigger the repeater to re-render, or in your case, remove the unnecessary item.

Hey
I do that but I must miss something, I will have to redo the whole thing to find the error. Thanks a lot for looking at it Ido.

Did anyone find the solution to this issue? I have the same problem

Hi @andreas-kviby ,
I Think you have syntex mistake.
It should be cartArray.splice(index,1); and not cartArray.splice[index,1];
Roi.