Play Framework: How to call a Javascript Function from a Scala Template -
i have scala template shows bunch of model objects , gives user option add or delete these objects.
each model object has location data associated it. i'd embed google map on page, , users manipulate (add,delete,edit,load) place marker each model object on map.
i can map loaded correctly, don't understand how call js functions scala template directly. template looks this:
@(stupas:list[stupa], stupaform:form[stupa]) @import helper._ <head> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=apikey"></script> <script type="text/javascript"> var map; function initialize() { var mapoptions = { center: { lat: -34.397, lng: 150.644}, zoom: 8 }; map = new google.maps.map(document.getelementbyid('map_canvas'), mapoptions); console.log("map should init now"); } google.maps.event.adddomlistener(window, 'load', initialize); function addlocation(lat, lon, name) { var latlng = new google.maps.latlng(lat,lon); var marker = new google.maps.marker({ position: mylatlng, title:name }); marker.setmap(map); } </script> </head> <body> <h1> stupas overview </h1> <div id="map_canvas" style="height: 430px; width: 512px; float:right; top:0px"></div> <ul> @for(stupa <- stupas) { <li>@stupa.stupaname</li> <ul> <li>description: @stupa.descritpion</li> <li>latitude: @stupa.latitude</li> <li>longitude: @stupa.longitude</li> <img src="@routes.stupacontroller.getimageforstupa(stupa.stupaname)"/> @form(routes.stupacontroller.delete(stupa.stupaname)) { <input type="submit" value="remove stupa"> } </ul> } </ul> @helper.form(action = routes.stupacontroller.submit, 'enctype -> "multipart/form-data") { @helper.inputtext(stupaform("stupaname")) @helper.inputtext(stupaform("description")) @helper.inputtext(stupaform("latitude")) @helper.inputtext(stupaform("longitude")) @helper.inputfile(stupaform("picture")) <button type="submit" onclick="" name="addprayer" >submit stupa</button> } </body>
i'd able call addlocation() function.
scala template cannot call javascript function scala template rendering page on server side , javascript function needs executed browser on/after loading page. in script can make document.ready function , inside call addlocation() function, use scala print parameter in function call. idea when browser execute function showing values not parameters.
Comments
Post a Comment