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.
Hi,
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?
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.
Thanks.
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.
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.
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.
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.
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('sc_tripbits.data.all_tripbits');
if (Array.isArray(markers)) {
markers.forEach(function(marker) {
console.log('LAT:' + marker.lat + ', LNG:' + marker.lng);
L.marker([marker.lat, marker.lng]).addTo(mymap);
});
}
}