我使用Rails和Hotwire (Turbo)动态更新我的页面,用户需要重新加载。
我有一个全局变量,它是一个数组,我在页面上循环它。例如
<% $listNumberPlates.each { |item| %>
<%= item %>
<% } %>现在,每当变量发生变化时,我都想更新它(不需要重新加载)。为了简化操作,我确实有一个更新变量的方法。
我试过用..。
<%= turbo_stream_from "listNumberPlatesStream" %>
<%= turbo_frame_tag "listNumberPlatesStream" do %>但我不知道怎么才能更新这些。任何帮助或建议都会得到很大的认可。谢谢。
发布于 2021-12-13 09:55:55
你可以用类似的东西:
after_create_commit do
broadcast_append_to [commentable, :comments], target: "#{dom_id(parent || commentable)}_comments", partial: 'comments/comment_with_replies', locals: { current_user: user }
end
after_update_commit do
broadcast_replace_to self, partial: 'comments/comment', locals: { current_user: user }
end
after_destroy_commit do
broadcast_action_to self, action: :remove, target: "#{dom_id(self)}_with_comments"
end在这种观点中,应该有这样的东西:
= turbo_stream_from @session, :comments
= tag.div id: "#{dom_id(@session)}_comments" do
= render partial: "comments/comments", collection: @session.root_comments, as: :comment, locals: { current_user: current_user }https://stackoverflow.com/questions/70332447
复制相似问题