gpt4 book ai didi

javascript - 谷歌API : Infowindow Content Issue

转载 作者:行者123 更新时间:2023-11-28 07:51:30 25 4
gpt4 key购买 nike

我正在尝试显示 marker在谷歌地图上。在 Google Maps API我从ajax获取数据并设置infowindow的内容。

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 条件吗?

最佳答案

使用+= 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
}

关于javascript - 谷歌API : Infowindow Content Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26750955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com