كيفية الانتقال من إرب إلى حمل جافا سكريبت
-
21-12-2019 - |
سؤال
أحاول تحويل ملف 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);
المحلول
جرب استخدام parseInt
:
L.polygon([parseInt(#{@start}),parseInt(#{@end})]).addTo(map);
لا تنتمي إلى StackOverflow