Reveal Modal 正在揭示循环迭代 Foundation-zurb 问题中的最后一个值
Reveal Modal is revealing last value in loop iteration Foundation-zurb issue
我正在使用 .each
in rails project_site
in index#action with foundation model reveal on each row 但
问题是模型显示在每个模型显示中只显示最后一个 project_site
的 ID。我想显示应该显示当前 project_site
.
的 ID
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<div class="full reveal" id="exampleModal1" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="exampleModal1"> View</button></p>
</td>
</tr>
<% end %>
每个模态都有相同的id,所以最后一个总是获胜。更改视图,使每一行的模态都有自己的 id,打开按钮调用正确的 id...
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<% site_modal_id = "site_modal_#{project_site.id}" %>
<div class="full reveal" id="<%= site_modal_id %>" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="<%= site_modal_id %>"> View</button></p>
</td>
</tr>
<% end %>
请注意,如果您有很多项目网站,您的页面速度会变慢,最好使用单一模式来传递点击数据。
我正在使用 .each
in rails project_site
in index#action with foundation model reveal on each row 但
问题是模型显示在每个模型显示中只显示最后一个 project_site
的 ID。我想显示应该显示当前 project_site
.
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<div class="full reveal" id="exampleModal1" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="exampleModal1"> View</button></p>
</td>
</tr>
<% end %>
每个模态都有相同的id,所以最后一个总是获胜。更改视图,使每一行的模态都有自己的 id,打开按钮调用正确的 id...
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<% site_modal_id = "site_modal_#{project_site.id}" %>
<div class="full reveal" id="<%= site_modal_id %>" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="<%= site_modal_id %>"> View</button></p>
</td>
</tr>
<% end %>
请注意,如果您有很多项目网站,您的页面速度会变慢,最好使用单一模式来传递点击数据。