Create string from repeater items

Hi,

I have a repeater that I use as a shopping cart, I would like when the customer selects the submit button for all the tour options they have in their shopping cart to save to my collection in a string format e.g. Dunn’s River Falls, Ultimate Zipline,

I have a written the following code that shows me the name of all the tours I have in the cart, but I can’t get them to save together.

$w(“#repeater1”).forEachItem ( ($item, itemData, index) => {

let tours = $item(“#text330”).text;

console.log(tours)

}); 

Please help

The information in the text item is also in the data attached to the repeater (assuming you aren’t using a dataset - otherwise it’s in a dataset).

You can access the data using the repeater data property

The you should be able to loop through the data and combine the specific properties in a string doing something like

let mergedString = “”;
for (let item of $(“#repeater1”).data) {
mergedString += item[‘tour’] + “,”;
}

Of course you would need to change the property name ‘tour’ for the correct name from the data array.

1 Like

Hi Steve,

Thank you so much! this worked like a charm!