谷歌api:信息窗口内容问题

Google api : Infowindow Content Issue

本文关键字:问题 窗口 信息窗 api 信息 谷歌      更新时间:2023-09-26

我正试图在谷歌地图上显示一个标记。在谷歌地图API中,我从ajax获取数据,并设置和信息窗口的内容。

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>']
];

当我使用if条件时,这段代码会出现语法错误,你能告诉我,我是如何在这段代码中使用if条件的吗。

使用+=赋值运算符向变量添加更多内容

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
}