Using data from rows in a table

Hi

I’ve successfully managed to get everything working from the below example…

I’m wanting to use the populated data in the repeater (which has the longitude and latitude details from the search in) as part of an onClick function attached to a button.

But, I’m not too sure how to ‘get/reference’ the data from each row in the repeater.

e.g:

let lat = $w("#repeater2").data ("_id": "2", text 4)
let lng = $w("#repeater2").data ("_id": "3", text 4)
$w("#text1").text = lat
$w("#text2").text = lng

Many thanks for any help!

Thomas

Hi,
You should use the onItemReady function to set the information to the repeater elements:

$w(`#repeater1`).onItemReady(($w, itemData) => {
   //itemData.fieldName (collection field name)
   $w(`#text1`).text = itemData.lat;
   $w(`#text1`).text = itemData.lng;
});

If the information saved in the fields is a number, you should parse it to string using the toString function.

Best,
Tal.

Hi Tal

Thanks for the reply.

I’ve already set the details to the repeater. Using the information given in the example here:

https://www.wix.com/code/home/forum/advanced-tips-tricks/how-to-use-google-maps-services-in-wix-code

This is the information it populates (all working fine at the mo):


However, I have a button that when clicked I want to save the longitude and latitude results from this repeater to a text element that I can later submit along with the rest of the information on the form.

Many thanks for the help

Thomas

Hey,
In this case, when setting the elements, you should assign an onClick event to the button when creating the repeater element:

$w(`#repeater1`).onItemReady(($w, itemData) => { 
    //itemData.fieldName (collection field name) 
    $w(`#button`).onClick(()=>{
            $w(`#text`).text = itemData.lat;
    }); 
});

Good luck,
Tal.

Hi Tal

Many thanks for your help! All working great.

Thomas