1

Я пытаюсь показать marker на Картах Google. В Google Maps API Я извлекаю данные из ajax и устанавливает и содержимое infowindow.Google api: Infowindow Content Issue

infoWindowContent = [ 
         ['<div class="info_content"><h3>'+ this.tc_city_name + '</h3>'+ if this.tc_city_description !=='null'){ +'<p>' + this.tc_city_description + '</p>'} + '<p><a href = "' + this.tc_city_web_site + '" target="_blank">' + this.tc_city_web_site + '</a></p>'+ '</div>'] 
]; 

Этот код, когда я использую ошибку, если условие, то это даст синтаксис, пожалуйста, вы можете сказать мне, как я использую, если условие в этом коде.

+0

'если (что-то) {infoWindowContent = '...'; } else {infoWindowContent = '...'; } ' – MrUpsidown

+0

, когда я использую условия для названия города, описания и веб-сайта, чем это может сделать мой код больше – Tarzan

+0

См. Мой ответ ниже. – MrUpsidown

ответ

0

Используйте +=assignment operator, чтобы добавить больше контента в переменную:

infoWindowContent = '<div class="info_content"><h3>' + this.tc_city_name + '</h3>'; 

if (this.tc_city_description !== 'null') { 
    infoWindowContent += '<p>' + this.tc_city_description + '</p>'; 
} 

infoWindowContent += '<p><a href = "' + this.tc_city_web_site + '" target="_blank">' + this.tc_city_web_site + '</a></p>' + '</div>'; 

Кстати вам не хватает ( в вашем if состоянии:

if (condition) { 
    // do something 
} 
+0

Спасибо, теперь его работа. – Tarzan