Problem with 2 repeaters

Hi Community,

I have some strange problem.
I have a repeater(“rpCataloog”) that is linked to a dataset (“dsCataloog”) .In this repeater i have a number called “afnamehoeveelheid”

I have another repeater (“rpWinkelmand”), this repeater is not linked to a dataset.

What i am trying to do is add the data from repeater “cataloog” to the other repeater “winkelmand”
Then when the itemId already exists it should take the “afnamehoeveelheid” from the repeater “winkelmand” and add the “afnamehoeveelheid” from the repeater “cataloog”

now the weird part is, that if i try to do so, both numbers go up.

Here are is my code:

$w.onReady(function () {
    $w("#rpWinkelmand").onItemReady(($item, itemData, index) => {
        $item("#txtOmschrijving").text = itemData.omschrijving
        $item("#txtArtNr").text = itemData.internartnr
        $item("#txtHoeveelheid").text = itemData.afnamehoeveelheid.toString()
        $item("#txtEenheid").text = itemData.eenheid
        $item("#txtKleur").text = itemData.kleur
        $item("#imgProduct").src = itemData.image
    })

    $w("#rpWinkelmand").data = []
    $w("#dsCataloog").onReady(() => {
        $w("#rpCataloog").onItemReady(($item, itemData, index) => {
            const _add = $item("#btnAdd")
            const _remove = $item("#btnRemove")

            _add.onClick((event) => {
                if ($w("#rpWinkelmand").data.length === 0) {
                    console.log("length === 0")
                    $w("#rpWinkelmand").data = [itemData]
                } else {
                    console.log("length > 0")
                    var data = $w("#rpWinkelmand").data
                    var bestaat = false
                    for (let i = 0; i < data.length; i++) {
                        console.log("itemData",itemData)
                        if (data[i]._id === itemData._id) {
                            bestaat = true
                            let value1 = Number(data[i].afnamehoeveelheid)
                            console.log("value1",value1)
                            let value2 = Number(itemData.afnamehoeveelheid)
                            console.log("value2",value2)
                            data[i].afnamehoeveelheid = value1 + value2
                            console.log("data hoeveelheid",data[i].afnamehoeveelheid)
                            $w("#rpWinkelmand").data = data
                        }

                    }
                    if (bestaat === false) {

                        data.push(itemData)
                        $w("#rpWinkelmand").data = data
                    }
                }

            })
            _remove.onClick((event) => {

            })
        })
    })
});

And here are some images of the page with the console.log.

Any idea why this happends?
Or what i can do about it?

It is just a small program for our company so we can put evrything in the “winkelmand” ,so we can order our profiles more easy.

Kind regards,
Kristof.

Could it be, that even when it are 2 repeaters, when they have the same _id in it that it changes both?

Could the afnamehoeveelheid still be linked to the dataset in both repeaters?

Hi @iaindowner ,
Thanks for your response.

I Checked it, but there is nothing linked in the repeater “winkelmand”
i also tried giving it a different _id when sending it over to the next repeater(“winkelmand”),
But seems like that also changes the ID from the first repeater (“cataloog”)

Tried even to loop trought the “winkelmand” data and change evry _id evrytime i add something.
Also changes all the data in the “cataloog” repeater.

@volkaertskristof Can’t see any reason why value2 would change from the value stored in your catalog repeater item based on your code. Only thing which might explain it is it is if $w ( “#txtHoeveelheid” ) in the rpWinkelmand repeater was linked to the dsCataloog catalogue. Then, when you are setting $w(“#rpWinkelmand”).data = data, it is updating the dataset field value and therefore value2 when you click the add button next. But if you have checked it and there is no link, I am not sure. Hopefully someone else can help.

@iaindowner
Seems like i found where the problem lies.

When adding data from one repeater to another i must be giving some special key with it. (not the “_id”)

I made 2 repeaters with the same “_id”'s
When changing repeater 1, it did not change the second 1.

But when i make 2 repeaters,
Then add data from repeater 1 to repeater 2 like this
var repeater1Data = $w(“#repeater1”).data
$w(“#repeater2”).data = repeater1Data

if i then change anything in repeater 1, it will also change in repeater 2.