【发布时间】:2019-03-22 23:55:37
【问题描述】:
我找到了一个可以在我正在工作的 Leaflet 项目中使用的函数。该函数是用 ES6 编写的,它在 Firefox 和 Chrome 中都运行良好。但是,我也需要针对 IE。在我的研究中,我发现 IE 目前不接受 ES6 箭头功能。我还发现如果将 ES6 函数转换为 ES5,该函数将在 IE 中运行。几天来,我试图将以下函数转换为 ES5,但没有成功。我尝试的一些解决方案在这里发布。有人可以看看我的脚本,让我知道我做错了什么。另外,无论如何,ES6 有什么好处?更短的脚本?提前谢谢你。
这是有效的 ES6 脚本:
points.map((p, i) => L.marker(p).bindPopup(`marker${'<strong>' + pointData[i].cityName + '</strong>' + ', ' + '</br>' + pointData[i].discrip + "<br /><a class='fancybox-thumb' ' style='width:150px;' rel='fancybox-button' rel='fancybox-thumb' data-fancybox-group='"+ pointData[i].popup +"' title='" + pointData[i].discrip + " ' href='graphic/"+ pointData[i].popup + "' ><img src='graphic/" + pointData[i].popup + "' alt='Image' ' style='width:150px;' ></a>" + "<br/><a href='http://www.google.com' target='_blank'>Cedellion Report</a>"}`))
.forEach(function(marker) {
map.addLayer(marker);
oms.addMarker(marker);
});
这是我最好的尝试/猜测,没有任何乐趣。
points.map(function(p, i) {
L.marker(p).bindPopup(`marker${'<strong>' + pointData[i].cityName + '</strong>' + ', ' + '</br>' + pointData[i].discrip + "<br /><a class='fancybox-thumb' ' style='width:150px;' rel='fancybox-button' rel='fancybox-thumb' data-fancybox-group='"+ pointData[i].popup +"' title='" + pointData[i].discrip + " ' href='graphic/"+ pointData[i].popup + "' ><img src='graphic/" + pointData[i].popup + "' alt='Image' ' style='width:150px;' ></a>" + "<br/><a href='http://www.google.com' target='_blank'>Cedellion Report</a>"}`)})
.forEach(function(marker) {
map.addLayer(marker);
oms.addMarker(marker);
});
【问题讨论】:
-
您遇到什么错误?当您在 IE 中运行您尝试的版本时?
-
脚本将崩溃,在控制台中我得到 Invalid character。
标签: javascript ecmascript-6 leaflet