我正在尝试将我的erb文件转换为haml。我想我可以对大部分代码进行字符串插值,但是在尝试使用JavaScript Leaflet函数时,我遇到了问题,L.polygon()(http://leafletjs.com/reference.html#polygon)只接受数字。 这是我的erb代码:
<h1>MAP!</h1>
<ul>
<li>Start: <%= @start %></li>
<li>End: <%= @end %></li>
</ul>
<div id="map"></div>
<script type="text/javascript" charset="utf-8">
var map = L.map('map').setView([40.7142, -74.0064], 13);
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Stamen Toner'}, {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
maxZoom: 18
}).addTo(map);
L.marker(<%= @start %>).addTo(map);
L.marker(<%= @end %>).addTo(map);
L.polygon([
<%= @start %>,
<%= @end %>
]).addTo(map);
</script>
这是我不太熟悉的HAML代码:
%h1 MAP!
%ul
%li
Start: #{@start}
%li
End: #{@end}
#map
%script{charset: "utf-8", type: "text/javascript"}
var map = L.map('map').setView([40.7142, -74.0064], 13);
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Stamen Toner'}, {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',maxZoom: 18}).addTo(map);
L.marker(#{@start}).addTo(map);
L.marker(#{@end}).addTo(map);
L.polygon([#{@start},#{@end}]).addTo(map);
答案 0 :(得分:1)
parseInt
:L.polygon([parseInt(#{@start}),parseInt(#{@end})]).addTo(map);