首页 > 解决方案 > javascript无法访问dom

问题描述

我有这段代码可以在 vanilla js 中使用,但在 Flask 模板引擎中不起作用。

在基本的 HTML-JS 中它没有任何问题,但不知何故我认为我在 Flask 中遗漏了一些东西。有什么我错过的吗?

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
{% extends 'layout.html' %}
{% block content %}

<body>

    <div id="map"></div>





     <script type="text/javascript">
        function initMap(){

            let map = new google.maps.Map(document.getElementById("map"), {
                center: { lat: -8.6478, lng: 115.1385 },
                zoom: 14,
              });

              alert("from initmap");

              var pointOfInterest = [
                {
                  position: {lat: -8.6595, lng: 115.1301},
                  price : '1000000',
                },
                {
                  position:{lat: -8.654355373797795, lng: 115.12441781895892},
                  price: '49999999'
                }
              ]

                pointOfInterest.map(prop =>{
                    console.log(prop);
                })


        }



    </script>
    <script
    src="https://maps.googleapis.com/maps/api/js?key=[redacted]&callback=initMap&v=weekly"
    async
    ></script>


</body>
{% endblock content %}
</html>

api 键没有任何问题,但我无法在 div 中显示谷歌地图。

标签: pythongoogle-mapsflask

解决方案


推荐阅读