繁体   English   中英

Google Maps infoWindow内容中的变量失败

[英]Variable in Google Maps infoWindow content fails

我有一个infoWindow,我想从一个变量中获取数据,但是每当我尝试运行它时,此代码都会一直失败。

没有变量,此代码可以正常工作:

content: "<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory

当我将内容分配给变量时:

  var infoWindow = new google.maps.InfoWindow({
var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

content: kontent
            });

我在行var kontent = ...遇到Unexpected token错误var kontent = ...

我该如何解决我的问题?

InfoWindow接收哈希。 在外部定义变量,然后根据需要使用它:

var kontent = "<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory;
var infoWindow = new google.maps.InfoWindow({
content: kontent
            });

infowindows :InfoWindow构造函数采用一个InfoWindowOptions对象文字,它指定用于显示信息窗口的初始参数。

这意味着,您需要更改以下内容:

 var infoWindow = new google.maps.InfoWindow({
        var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

        content: kontent
 });

至:

var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='
        "+mid+"
        ' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

var infoWindow = new google.maps.InfoWindow({
      content: kontent
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM