代码之家  ›  专栏  ›  技术社区  ›  Victor

i+1内部rails散列代码?

  •  0
  • Victor  · 技术社区  · 15 年前

    尝试生成 map_blue_1.png , map_blue_2.png ,等等,但在 {i+1} . 正确的方法是什么?

    <% content_for :in_script do %>
        $("#map").gMap({ 
            markers: [
                      <% @spots.each_with_index do |spot, i| %>
                        <% if spot.geocoded? %>
                        {
                          latitude: <%= spot.lat %>,
                          longitude: <%= spot.lng %>,
                          html: "<a href='#item_<%= i + 1 %>'><strong><%=h spot.name %></strong></a>",
                          icon: { image: "<%= APP_CONFIG[:site_url] + '/images/map_blue_' + {i+1} + '.png' %>",
                                  iconsize: [48, 48],
                                  iconanchor: [24,48],
                                  infowindowanchor: [24, 0] }
                        },
                        <% end %>
                      <% end %>
                     ],
            zoom: 12 });
    <% end %>
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   jordinl    15 年前

    APP_CONFIG[:site_url] + '/images/map_blue_' + (i+1).to_s + '.png'

    或

    "#{APP_CONFIG[:site_url]}/images/map_blue_#{i+1}.png"