JS错误:不要在循环中创建函数

时间:2018-01-25 02:24:36

标签: javascript loops

坚持审核错误: 不要在循环中创建函数

错误可以在:

找到
    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: {
            lat: -34.60,
            lng: -58.38
        },
        zoom: 13,
        mapTypeControl: false
    });
    var largeInfowindow = new google.maps.InfoWindow();
    var bounds = new google.maps.LatLngBounds();
    for (var i = 0; i < locations.length; i++) {
        var position = locations[i].location;
        var title = locations[i].title;
        var marker = new google.maps.Marker({
            map: map,
            position: position,
            title: title,
            animation: google.maps.Animation.DROP,
            id: i
        });

        markers.push(marker);

        marker.addListener('click', function() {
            var self = this;
            populateInfoWindow(this, largeInfowindow);
            this.setAnimation(google.maps.Animation.BOUNCE);
            setTimeout(function() {
                self.setAnimation(null);
            }, 1400);
        });
        bounds.extend(markers[i].position);
    }

    map.fitBounds(bounds);
    viewModel = new AppViewModel();
    ko.applyBindings(viewModel);

}

项目可在以下位置找到: https://github.com/storchia/Neighborhood

任何帮助都将受到高度赞赏!!!

0 个答案:

没有答案