2012-07-27 82 views
0

我使用Smarty的,我想使用谷歌地圖,並在其上動態地位置標記,我得到了下面的鱈魚智者和谷歌地圖

{literal} 

<script type="text/javascript"> 
    //<![CDATA[ 

    if (GBrowserIsCompatible()) { 
     // ==== first part of the select box === 
     var select_html = '<select onChange="handleSelected(this)">' + 
         '<option selected> - Select a location - <\/option>'; 
     // ===================================== 
     var gmarkers = []; 
     var htmls = []; 
     var i = 0; 
     var rozmiar = new google.maps.Size(12,20); 
       var punkt_startowy = new google.maps.Point(0,0); 
       var punkt_zaczepienia = new google.maps.Point(0,0); 
       var map; 
     var n=0; 
     var side_bar_html = ""; 


     var icon = new GIcon(); 
     icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; 
     icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; 
     icon.iconSize = new GSize(12, 20); 
     icon.shadowSize = new GSize(22, 20); 
     icon.iconAnchor = new GPoint(6, 20); 
     icon.infoWindowAnchor = new GPoint(5, 1);  


     var ikona1 = new GIcon(icon,"http://labs.google.com/ridefinder/images/mm_20_blue.png"); 

     // A function to create the marker and set up the event window 
     function createMarker(point,name,html,ikon) { 
      var options = { 
draggable: true, 
title: name, 
icon: ikon, 
clickable:true} 
     var marker = new GMarker(point,options); 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     }); 
     gmarkers[i] = marker; 
     htmls[i] = html; 

     // ======= Add the entry to the select box ===== 
     select_html += '<option> ' + name + '<\/option>'; 
     // ========================================================== 

     i++; 
     map.addOverlay(marker); 
     return marker; 
     } 


     // ======= This function handles selections from the select box ==== 
     // === If the dummy entry is selected, the info window is closed == 
     function handleSelected(opt) { 
     var i = opt.selectedIndex - 1; 
     if (i > -1) { 
      GEvent.trigger(gmarkers[i],"click"); 
     } 
     else { 
      map.closeInfoWindow(); 
     } 
     } 

     var wspolrzedne = new google.maps.LatLng(51.730430542940184,19.62158203125); 

     // create the map 
     var map = new GMap2(document.getElementById("map")); 
     map.addControl(new GLargeMapControl()); 
     map.addControl(new GMapTypeControl()); 
     map.setCenter(new GLatLng(51.730430542940184,19.62158203125), 6); 

    {/literal} 
    {foreach from=$znacznik key=key item=item} 
    {foreach from=$item key=k item=v} 
    //here 
      createMarker(new GLatLng(51.730430542940184,19.62158203125),'{if $k == 'nazwa_obiektu'}{$v}{/if}','<div class="dymek"><div style="border-bottom:2px solid red;margin-bottom:6px;text-align:left;"><a href="http://nocleg-i.pl/{if $k == 'id'}{$v}{/if}/google_maps/" style="color:#2A86C7;font-size:13px;font-family:Verdana;font-weight:bold;">{if $k == 'nazwa_obiektu'}{$v}{/if}</a></div></strong><div style="float:left;width:125px;"><strong><a href="http://nocleg-i.pl/{if $k == 'id'}{$v}{/if}/google_maps/"><img src="http://nocleg-i.pl/uzytkownicy/miroslawa/mini_0.jpg" alt="" border="0" /></a></div>Miasto: {if $k == 'miasto'}{$v}{/if}</div></div><div style="clear:both;"></div>',ikona1); 
    //here 
    {/foreach} 
    {/foreach} 
    {literal} 
      }else { 
     alert("Sorry, the Google Maps API is not compatible with this browser"); 
    } 

    // This Javascript is based on code provided by the 
    // Community Church Javascript Team 
    // http://www.bisphamchurch.org.uk/ 
    // http://econym.org.uk/gmap/ 

    //]]> 
    </script> 
    {/literal} 

標籤之間(//此處) 這些代碼問題

createMarker(new GLatLng(51.730430542940184,19.62158203125),'{if $k == 'nazwa_obiektu'}{$v}{/if}','<div class="dymek"><div style="border-bottom:2px solid red;margin-bottom:6px;text-align:left;"><a href="http://nocleg-i.pl/{if $k == 'id'}{$v}{/if}/google_maps/" style="color:#2A86C7;font-size:13px;font-family:Verdana;font-weight:bold;">{if $k == 'nazwa_obiektu'}{$v}{/if}</a></div></strong><div style="float:left;width:125px;"><strong><a href="http://nocleg-i.pl/{if $k == 'id'}{$v}{/if}/google_maps/"><img src="http://nocleg-i.pl/uzytkownicy/miroslawa/mini_0.jpg" alt="" border="0" /></a></div>Miasto: {if $k == 'miasto'}{$v}{/if}</div></div><div style="clear:both;"></div>',ikona1); 

它不顯示變量爲ex。 {if $ k =='nazwa_obiektu'} {$ v} {/ if}}什麼都不顯示,當我在其他地方顯示函數時顯示它的變量,但是如果我手工輸入它,顯示它 有人想過如何解決它?

+0

嘗試使用情商,而不是== – 2012-07-27 14:15:22

回答

1

檢查您的撇號結構如何。試試這個還是看{assign}到預先設定爲JavaScript值,避免撇號混亂

createMarker(
    new GLatLng(51.730430542940184,19.62158203125), 
    '{if $k == "nazwa_obiektu"}{$v}{/if}', 
    '<div class="dymek"><div style="border-bottom:2px solid red;margin-bottom:6px;text-align:left;"><a href=\"http://nocleg-i.pl/{if $k == "id"}{$v}{/if}/google_maps/\" style=\"color:#2A86C7;font-size:13px;font-family:Verdana;font-weight:bold;\">{if $k == "nazwa_obiektu"}{$v}{/if}</a></div></strong><div style=\"float:left;width:125px;\"><strong><a href=\"http://nocleg-i.pl/{if $k == "id"}{$v}{/if}/google_maps/\"><img src=\"http://nocleg-i.pl/uzytkownicy/miroslawa/mini_0.jpg\" alt=\"\" border=\"0\" /></a></div>Miasto: {if $k == "miasto"}{$v}{/if}</div></div><div style=\"clear:both;\"></div>', 
    ikona1 
); 

或{}分配

{if $k == "nazwa_obiektu"} 
    {assign var="nazwa_obiektu" value=$v} 
{/if} 

{if $k == "id"} 
    {assign var="id" value=$v} 
{/if} 

{if $k == "miasto"} 
    {assign var="miasto" value=$v} 
{/if} 

    createMarker(
     new GLatLng(51.730430542940184,19.62158203125), 
     '{$nazwa_obiektu|default}', 
     '<div class="dymek"><div style="border-bottom:2px solid red;margin-bottom:6px;text-align:left;"><a href=\"http://nocleg-i.pl/{$id|default}/google_maps/\" style=\"color:#2A86C7;font-size:13px;font-family:Verdana;font-weight:bold;\">{$nazwa_obiektu|default}</a></div></strong><div style=\"float:left;width:125px;\"><strong><a href=\"http://nocleg-i.pl/{$id|default}/google_maps/\"><img src=\"http://nocleg-i.pl/uzytkownicy/miroslawa/mini_0.jpg\" alt=\"\" border=\"0\" /></a></div>Miasto: {$miasto|default}</div></div><div style=\"clear:both;\"></div>', 
     ikona1 
    ); 
0

你的問題是報價:

"{if $k == 'nazwa_obiektu'}{$v}{/if}" 
//^----------use double quotes--------^ 
0

你需要或者逃避你的報價,或使用不同的:

'{if $k == 'nazwa_obiektu'...}' 

應該

'{if $k == \'nazwa_obiektu\'...}' 

OR

'{if $k == "nazwa_obiektu"...}' 
+0

@ariel使用帶語法高亮的IDE - 這將使這個問題在未來更容易解決。 – Matt 2012-07-27 14:17:10