Nicole S Campbell
Nicole S Campbell

Reputation: 29

Changing the data of the repeater in wix

I'm trying to manipulate the repeater list in Wix. When the user selects the quantity of equipment, that number of forms show up. I got the hang of it when I see it in the console log but when I try to display it on the web, it gives me an error. I've tried reassigning $w("#repeater1").data to newArr(the new data).

Here's my code

$w("#repeater1").hide();
    let itemOptions = $w("#quoteDropdown").options

    $w("#quoteDropdown").onChange((event) => {  
        $w("#repeater1").show();

        const arrOfValues = []
        let newArr = []
        let repeaterData = $w("#repeater1").data;    
        let quantity = Number(event.target.value);

        let iterator = repeaterData.values();
        for(const value of iterator) {
            arrOfValues.push(value);
        }

        for(let i = 0 ; i < itemOptions.length; i++) { 
            newArr = repeaterData.slice(0, quantity);
        }        

        if(quantity > newArr.length) {
            let newItems = arrOfValues.filter(arr => {
                newArr.forEach(na => arr !== na)
            })
            newArr.push(newItems)
        }
        console.log("newArr");
        console.log(newArr);

         // $w("#repeater1").data is the original data from the repeater
         // newArr is the altered data from the repeater based on how it appears based on the users' interaction.
         
         // I've tried each one of these
         // $w("#repeater1").data = newArr;
        // return newArr;
 
    }); // end onChange 

Upvotes: 0

Views: 618

Answers (1)

Sam
Sam

Reputation: 1109

If you're trying to assign the array as the data for a repeater, you need to follow some rules. First, it needs to be an array of objects. Second, each object needs to have an _id property.

Upvotes: -1

Related Questions