未执行Google Map信息窗口中HTML内容的javascript

时间:2018-10-11 18:12:59

标签: javascript jquery ajax google-maps google-maps-markers

我有以下JSON文件:

{
  name: 'confirmPassword',
  label: t('user:Confirm password'),
  value: itemData.confirmPassowrd,
  type: 'password',
  validators: ({ field, form }) => [
    field.value === form.$('password').value,
    'Passwords do not match.',
  ],
}

基于此数据,我正在创建3个标记。

{
   "places" : [
    {
        "place": "A",
        "place_id": "ChIJIQs8RmOQdkcRkR07PeyDqhw",
        "lat": 47.803488,
        "lng": 13.045824
    },
    {
        "place": "B",
        "place_id": "ChIJY60NGmOQdkcRnHyLQNKMWOg",
        "lat": 47.802524,
        "lng": 13.046177
    },
    {
        "place": "​C",
        "place_id": "ChIJKR11Md-QdkcRIcl4Mu8D0DA",
        "lat": 47.773108,
        "lng": 13.069841
    }
  ]
}

调用的infowindowcontent.html代码如下:

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 9,
    center: new google.maps.LatLng(47.5,13.2)
});

var infowindow = new google.maps.InfoWindow();
var json = "http://127.0.0.1/json/data.json";
$.getJSON(json, function(json1) {
    $.each(json1.places, function (key, data) {
        var latLng = new google.maps.LatLng(data.lat, data.lng);
        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            title: data.place
        });

        bindInfoWindow(marker, map, infowindow, data.place_id);

    });
});
}

function bindInfoWindow(marker, map, infowindow, myPlace) {
google.maps.event.addListener(marker, 'click', function () {
    $.ajax({
        url: 'infowindowcontent.html?place_id=' + myPlace,
        dataType: 'html',
        success: function(data) {
                infowindow.setContent(data);
                infowindow.open(map, marker);
        }
    }); 
});
}

每个代码都可以正常工作。 但是,通过单击标记可以调用infowindowcontent.html代码。显示信息窗口,但未执行javascript。我还是读“不,不,不”,而不是“嘿,嘿,嘿”。有什么建议么?谢谢。

0 个答案:

没有答案