如何从 HAML 的 :javascript 中运行每个块?
我决定将我的模板技术更新为 HAML。我是新手,想知道这是否可能:
:javascript
<% @checkins.each do |checkin| %>
var latLng = new google.maps.LatLng(<%= checkin.latitude %>, <%= checkin.longitude %>);
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: '<%= escape_javascript(checkin.title) %>'
});
google.maps.event.addListener(marker, 'click', function() {
document.location = '<%= checkin_path(checkin) %>';
});
<% end %>
很容易看出我遇到问题的代码部分是与 Ruby 代码相关的部分
<% @checkins.each do |checkin| %>
,或者
document.location = '<%=checkin_path(checkin) %>';
我尝试将后者更改为:
- @checkins.each do |checkin|
但它是到目前为止还没有发挥作用。我已经在这里阅读了许多关于同一主题的其他问题,但我还没有真正找到“直接”的答案。
I decided to update my templating technology to HAML. I'm new to it, and wondered if this is possible at all:
:javascript
<% @checkins.each do |checkin| %>
var latLng = new google.maps.LatLng(<%= checkin.latitude %>, <%= checkin.longitude %>);
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: '<%= escape_javascript(checkin.title) %>'
});
google.maps.event.addListener(marker, 'click', function() {
document.location = '<%= checkin_path(checkin) %>';
});
<% end %>
It's easy to see that the parts of the code I'm having problems with are the ones related to Ruby code
<% @checkins.each do |checkin| %>
or
document.location = '<%=checkin_path(checkin) %>';
I tried to change the latter to:
- @checkins.each do |checkin|
but it's not working out so far. I already read many other questions here about the same topic, but I haven't really been able to find a 'straight-forward' answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试替换
<% @checkins.each do |checkin| %>
为,并将
end
语句替换为}
同时将
<%= %>
替换为签入.whateverproperty
Try replacing
<% @checkins.each do |checkin| %>
withand replace your
end
statement with}
Also replace your
<%= %>
with justcheckin.whateverproperty