首页 > 解决方案 > 到特定 div 的动作电缆

问题描述

我正在寻找可以根据 stream.id 更改的特定 div。

我有以下内容:

ActionCable.server.broadcast('webconferencier_channel', participants_html: participants_html, stream_id: webconferencier.stream_id)

我在哪里通过stream_id.

我希望像这样在咖啡文件中检索它:

    received: (data) ->
  # Called when there's incoming data on the websocket for this channel
      participantsHtml = data.participants_html
      $('#show_participants' + data.stream_id).html(participantsHtml);

然后将视图更新为:

<div id="show_participants_#{<%= @stream.id %>}">
</div>

我可以看到 AC 发送带有其他变量的 div 模板,但我似乎无法检索和更新它。我认为我的咖啡语法不正确。

在视图中,div id 显示为:

<div id="show_participants_#{67089dbd-9826-41f2-97bc-b774b667ef66}">
</div> 

UUID 与我通过咖啡文件传递的字符串完全相同。有谁知道我该怎么做?谢谢

标签: ruby-on-rails

解决方案


id您应该从 div 的like中删除花括号和 octothorp show_participants_UUID

您可以将 console.log 添加到咖啡中,以查看里面发生了什么。


推荐阅读