【问题标题】:Rails 7 + Hotwire/Turbo: `turbo_frame_tag` not rendering where it shouldRails 7 + Hotwire/Turbo:`turbo_frame_tag` 未在应有的位置呈现
【发布时间】:2022-12-29 01:27:44
【问题描述】:

我正在创建一个表,我想在每一行周围呈现一个 turbo-frame 标记。

这是 html.erb 文件中的代码(参见第 7 行)。

 1. <table class="min-w-full divide-y divide-gray-300">
 2.   <thead>
 3.     ...
 4.   </thead>
 5.   <tbody>
 6.     <% current_organization.users.each do |user| %>
 7.       <%= turbo_frame_tag member do %>
 8.         <%= render partial: "user/row", locals: {user: user} %>
 9.       <% end %>
10.    <% end %>
18.   </tbody>
19. </table>

检查生成的 HTML,turbo-frame 标记呈现在表格外部并且其中没有内容(请参阅第 1 行和第 2 行)。

1. <turbo-frame id="user_2"></turbo-frame>
2. <turbo-frame id="user_3"></turbo-frame>
3. <table>
4.   ...
5. </table>

知道为什么会这样吗?

【问题讨论】:

  • 表格中只允许使用几个标签:thead、tbody、tr ... developer.mozilla.org/en-US/docs/Web/HTML/Element/table。为什么需要所有这些涡轮增压车架?
  • 谢谢,@Alex。我认为可能是这种情况,但我没想到会被 Rails 或 TurboFrames 强制执行。是浏览器做的吗?我需要每一行周围的 TurboFrames,以便它们可以通过 TURBO_STREAM 响应动态更新。
  • 由浏览器强制执行。你不需要涡轮框架,只需在tr标签上添加独特的id

标签: ruby-on-rails hotwire-rails turbo-rails


【解决方案1】:

https://github.com/hotwired/turbo/issues/48

table 元素只允许某些元素作为子元素。因此,它踢出了涡轮框架元素。 您必须通过将表格元素和 turbo frame 标签包装在 div 中来解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2022-01-16
    • 2022-12-04
    相关资源
    最近更新 更多