[英]How to go from Erb to Haml Javascript
I'm trying to convert my erb file into haml. 我正在尝试将erb文件转换为haml。 I figured I could string interpolate most of my code but I'm running into issues when trying to use a JavaScript Leaflet function, L.polygon() ( http://leafletjs.com/reference.html#polygon ), that only accepts numbers. 我认为可以对大多数代码进行字符串插值,但是在尝试使用仅接受JavaScript的Leaflet函数L.polygon()( http://leafletjs.com/reference.html#polygon )时遇到问题数字。 Here's my erb code: 这是我的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>
And here's my not quite working HAML code: 这是我不太有效的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);
parseInt
: L.polygon([parseInt(#{@start}),parseInt(#{@end})]).addTo(map);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.