我已将 data-turbolinks-permanent 添加到 div:
<div id="map" data-turbolinks-permanent></div>
但是在更改页面并返回时,我的 map 标记消失了。
下面是我包含js的方式:
<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3&key=key&libraries=places&callback=loadMap", "async" => true, "defer" => true -%>
<%= javascript_include_tag 'map.js' -%>
当我包含 data-turbolinks-track => 重新加载到谷歌地图时,js 包含在页面更改时显示的标记,但它当然会重新加载;我希望元素和 js 在页面加载时保持不变。
注意:gmaps js include 中的 key 参数是为了隐藏我的 API key
最佳答案
我决定使用 locationStorage 和 sessionStorage HTML5 API;我需要的是在返回时记住应用程序的状态:
从 #map div 中删除了 data-turbolinks-permanent,然后在 google map api js 包含中使用了“data-turbolinks-track => reload”,然后使用了 localStorage 和 sessionStorage API。
关于javascript - data-turbolinks-permanent 阻止 js 运行并摆脱谷歌地图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43915538/