data-turbolinks-permanent防止js运行&摆脱谷歌地图标记

时间:2017-05-11 12:33:10

标签: javascript ruby-on-rails google-maps-api-3 turbolinks

我已将数据 - turbolinks-permanent添加到div:

<div id="map" data-turbolinks-permanent></div>

但在更改页面并返回时,我的地图标记会消失。

以下是我包含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 =&gt;重新加载到谷歌地图js包括标记显示页面更改,但它当然重新加载;我希望元素和js能够在页面加载中持续存在。

注意:gmaps js include中的关键参数旨在隐藏我的API密钥

1 个答案:

答案 0 :(得分:1)

I have instead decided to use locationStorage and sessionStorage HTML5 API's; What I needed was to remember the state of the application when going back:

Removed the data-turbolinks-permanent from the #map div and then used the 'data-turbolinks-track => reload' on the google map api js include and then used the localStorage & sessionStorage API's.

About localStorage and sessionStorage