[英]passing data to modal(bootstrap)
我在Google地图上有多个标记,当我单击它们时,我需要打开一个模式窗口。 问题是每个标记都有一个特定的ID,我需要在每个模式中使用该ID。
模态html是:
<div class="modal fade" id="imageModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
调用此函数的javascript代码为:
function createMarker(pos, t, map) {
var marker = new google.maps.Marker({
position: pos,
map: map, // google.maps.Map
index: t
});
google.maps.event.addListener(marker, 'click', function() {
$('#imageModal').modal();
//alert("I am marker " + marker.index);
});
return marker;
}
因此,在imageModal中,我需要访问动态的marker.index信息。 我怎样才能做到这一点? 有任何想法吗 ?
首先,我认为index
不是Google Maps v3中的MarkerOption 。
我的方法是,我在MarkerOption中使用了title
选项,并将其设置为动态字符串,然后在addListener
事件中对其进行了访问。
您可以按照以下方法进行操作:
function createMarker(pos, t, map) {
var marker = new google.maps.Marker({
position: pos,
map: map, // google.maps.Map
title: t //where t must be a string
});
google.maps.event.addListener(marker, 'click', function() {
$('#imageModal').modal();
alert("I am marker " + this.getTitle() );
});
}
希望这对您有帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.