Getting variable value from repeater into javascript

I’m trying to get lat/lng from a repeater to make leaflet markers. I’ve tried every different variation of formatting I can think of and nothing returns the value.

<div class="row" is="dmx-repeat" id="repeat1" dmx-bind:repeat="">
        var marker = L.marker([dmx.parse(''), dmx.parse('' )]).addTo(mymap); 

Thanks for any pointers!

Did you debug it? Does it return any values?
Do you get a value without the repeat?
I mean if you just bind a value out of the repeat does it display the first value?

Sorry, yes, I should have said. I have two paragraph elements that are returning the values

<p dmx-text="lat"></p>, <p dmx-text="lng"></p>

However, i tried binding it outside the repeat like so…

<p>TEST: {{repeat1[0].lat}}</p>

and nothing was returned. That’s the Wappler generated code. Nothing is returned even if I put that back inside the repeat.

This returns the first value whether inside or outside the repeat
<p>TEST: {{[0].lat}}</p>


Further - I’ve tried using a new page and a different table/repeater.

	<div class="contentArea">
		<div id="repeat1" is="dmx-repeat" dmx-bind:repeat="">
			<p dmx-text="'1' + trip_name"></p>
			<p dmx-text="'2' +[0].trip_name.value()"></p>
			<p dmx-text="'3' +[0].trip_name.getValue()"></p>
			<p dmx-text="'4' +"></p>
			<p dmx-text="'5' +"></p>
			<p dmx-text="'6' +[0].trip_name.value"></p>
			<p dmx-text="'7' +[0].trip_name.getValue"></p>
			<p dmx-text="'8' +"></p>
			<p dmx-text="'8' +"></p>
			<p dmx-text="'9' + repeat1.trip_name.value"></p>
			<p dmx-text="'10' + repeat1.trip_name.getValue"></p>
			<p dmx-text="'11' + repeat1.trip_name.value"></p>
			<p dmx-text="'12' + repeat1.trip_name.getValue"></p>
			<p dmx-text="'13' + repeat1.trip_name"></p>
			<p dmx-text="'14' + repeat1[0].trip_name"></p>
			<p dmx-text="'15' + repeat1[0].trip_name.value"></p>
			<p dmx-text="'16' + repeat1[0].trip_name.getValue"></p>
			<p dmx-text="'17' + {{trip_name}}"></p>


The first and last of those are the only ones that print out the trip_name. And they all send the same error message to the console.

parser.js:384 TypeError: Cannot read property 'get' of undefined
    at t (parser.js:649)
    at parser.js:731
    at parser.js:731
    at parser.js:718
    at parser.js:731
    at parser.js:699
    at parser.js:449
    at Object.dmx.parse (parser.js:382)
    at testing.php:39
dmx.parse @ parser.js:384
(anonymous) @ testing.php:39
testing.php:39 undefined

I could just write some php code to get the data directly, but I’d really rather do this the Wappler way if possible.

could you share url for check

I’ve been working on this all day so none of what I posted there is still there. I’ve searched the docs and can’t find anything where someone has managed to get a value inside a repeat into javascript. Maybe it’s not possible? I’ve tried setting php variables, setting cookies/sessions, etc, etc and nothing works.

I can put all that back in but I don’t think it would be helpful.

When I got this error It was data type error. I mean that I was trying to read a string as a number.

Try something like this and throw it inside the repeat
to check if you ll get something

Thanks. That makes sense and works inside the repeat, but not parsing it in script.

{{[$index].lat}} <!--works-->
    console.log(dmx.parse("{{[$index].lat}}")) //doesn't work

Please a try again with remove double quotas

Why are you adding the script block inside the repeater? I wouldn’t advice using script blocks in the middle of your html.

I’m not sure what you want to do, but you could better put the javascript inside a function and call it in an event, for example the load event of serverconnect or the updated event from your repeater.

Removing double quotes throws an error.

Uncaught SyntaxError: Unexpected token ‘{’

Hey Patrick,

In this particular instance I need to create a marker for my map and then place it on the map. I’m using leaflet as I don’t want to use Google maps (which are insanely expensive now!).

I have this working in a standalone app that I wrote using php/mysql for the data and already have all the scripts written from that. I just boiled it down to the simplest example to figure out how to get the lat/lng variable from the repeater.

I just tried …

<div class="row" is="dmx-repeat" id="repeat1" dmx-bind:repeat="" dmx-on:updated="mapMarker({{[$index].lat}})">

with the function outside the repeater at the end of my code with the rest of the javascript functions

function mapMarker(lat){console.log("LAT:" + lat);}

it returns “Lat: undefined”

So the problem is still, how to get a value from the repeater into javascript.

Maybe if you, or someone else, has a few minutes you could mock it up and see if you can get a value from a repeater into a script? I’m starting to think it might be a backend issue with Wappler, rather than a syntax issue on my end.


Hi Heather,

Have you tried this?

<div class="row" is="dmx-repeat" id="repeat1" dmx-bind:repeat="" dmx-on:updated="mapMarker({{lat}})">

EDIT: might also want dmx-on:changed instead of updated. But also, this isn’t an input so it won’t be changed, right?

use onsuccess="setMapMarkers()" on the server connect component. In the javascript function get the data from the server connect, loop through them and do your work.

function setMapMarkers() {
  var markers = dmx.parse('');

  if (Array.isArray(markers)) {
    markers.forEach(function(marker) {
      console.log('LAT:' + + ', LNG:' + marker.lng);
      L.marker([, marker.lng]).addTo(mymap);

Patrick!!! My Hero!!! That works perfectly. Thanks!!!