0

所以基本上,我想用 Ruby on Rails 循环记录散列来填充 twitter 引导程序:

var popup = '<div id='+ key +' class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' + 
    '<div class="modal-body">'+  
        <% v.each_with_index do |s, i| %>
            <%= i %>
        <% end %> 

    '</div>' + 
'<div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button></div>' + '</div>'

$(popup).appendTo("body");

然而它只给了我第一个元素...... 0

PS日期在哈希中是100%

4

2 回答 2

1

您错过了(可能输入错误):

<%= v.each_with_index do |s, i| %>

如果您想在.erb模板中运行 Ruby 语句。

于 2013-06-03T06:40:22.137 回答
1

将其更改为

var popup = '<div id='+ key +' class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' + '<div class="modal-body">'
<% v.each_with_index do |s, i| %>
  popup = popup + <%= i %>
<% end %>
popup = popup + '</div>' + '<div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button></div>' + '</div>'
于 2013-06-03T08:11:34.693 回答