html - How to pass values from mustache to JavaScript? -


when generating html, can fetch properties json objects need calling

{{cmpyjson[jobcmpyid].company_name}} 

then html include "google", "amazon" or other objects asked.

however, when try

<script>   var company = cmpyjson[jobcmpyid].company_name </script> 

company assigned null.

so how go setting company value string obtainable html?

here overall page trying generate:

<head>     <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <title>google maps javascript api v3 example: geocoding simple</title>     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>     <script type="text/javascript">       var geocoder;       var map;       var address = "lamar ";       //address = "austin, tx";       //var address ={{cmpyjson[jobcmpyid].company_name}}       //address +=" company, ";       address += locjson[joblocid].location_name;       function initialize() {         geocoder = new google.maps.geocoder();         var latlng = new google.maps.latlng(-34.397, 150.644);         var myoptions = {           zoom: 11,           center: latlng,         maptypecontrol: true,         maptypecontroloptions: {style: google.maps.maptypecontrolstyle.dropdown_menu},         navigationcontrol: true,           maptypeid: google.maps.maptypeid.roadmap         };         map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions);         if (geocoder) {           geocoder.geocode( { 'address': address}, function(results, status) {             if (status == google.maps.geocoderstatus.ok) {               if (status != google.maps.geocoderstatus.zero_results) {               map.setcenter(results[0].geometry.location);                  var infowindow = new google.maps.infowindow(                     { content: '<b>'+address+'</b>',                       size: new google.maps.size(150,50)                     });                  var marker = new google.maps.marker({                     position: results[0].geometry.location,                     map: map,                      title:address                 });                  google.maps.event.addlistener(marker, 'click', function() {                     infowindow.open(map,marker);                 });                } else {                 alert("no results found");               }             } else {               alert("geocode not successful following reason: " + status);             }           });         }       }     </script>     </head>     <body style="margin:0px; padding:0px;" onload="initialize()">      <div id="map_canvas" style="width:100%; height:200px;"></div>     </body> 

i think make sense put company name html , then, in js, parse html. example:

<script>   // …   var address = document.getelementybyid('company-name');   // … </script> </head> <body style="margin:0px; padding:0px;" onload="initialize()">  <div id="map_canvas" style="width:100%; height:200px;">    should map showing location of <span id="company-name">{{cmpyjson[jobcmpyid].company_name}}</span>.  </div> </body> 

that way, nice fallback when map fails load.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -