Javascript ActionCable聊天,JS console.log不';行不通
我正在用ActionCable聊天。我想要普通的、公共的、私人的房间和直接的信息(比如Slack) 公共房间和DMs正在工作。我还可以创建私人房间并添加用户。但我想用某种方式通知用户,他被添加到了私人房间。现在,用户需要刷新他添加到聊天列表中的新聊天室的页面 我开始慢慢地抓住这一刻,当用户被其他用户添加时,我想把一些东西写入控制台并链接到这个新房间,但它不起作用。“聊天室未激活”显示有人在聊天室中写入用户所属的内容,但在这种特定情况下(添加到新创建的聊天室中),它根本不会显示,链接也是如此Javascript ActionCable聊天,JS console.log不';行不通,javascript,ruby-on-rails,actioncable,Javascript,Ruby On Rails,Actioncable,我正在用ActionCable聊天。我想要普通的、公共的、私人的房间和直接的信息(比如Slack) 公共房间和DMs正在工作。我还可以创建私人房间并添加用户。但我想用某种方式通知用户,他被添加到了私人房间。现在,用户需要刷新他添加到聊天列表中的新聊天室的页面 我开始慢慢地抓住这一刻,当用户被其他用户添加时,我想把一些东西写入控制台并链接到这个新房间,但它不起作用。“聊天室未激活”显示有人在聊天室中写入用户所属的内容,但在这种特定情况下(添加到新创建的聊天室中),它根本不会显示,链接也是如此 Ap
App.chatrooms = App.cable.subscriptions.create "ChatroomsChannel",
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) ->
active_chatroom = $("[data-behavior='messages'][data-chatroom-id='#{data.chatroom.id}']")
if active_chatroom.length > 0
console.log 'chatroom is active"
active_chatroom.append("<div class='message'>
<a href='' class='message_profile-pic'></a>
<a href='' class='message_username'><strong>#{data.email}</strong></a>
<span class='message_star'></span>
<span class='message_content'>
#{data.body}
</span>
</div>")
debugger
else
console.log 'chatroom isnt active'
$("[data-behavior='chatroom-link'][data-chatroom-id='#{data.chatroom.id}']").css("font-weight", "bold")
chatroom_id = data.chatroom.id
$('tbody').append("<tr><td><a href='/chatrooms/#{data.chatroom.id}'>Name</a></td></tr>")
$messages = $('#messages')
$messages.scrollTop $messages.prop('scrollHeight')
speak: (chatroom_id, message) ->
@perform 'speak', {chatroom_id: chatroom_id, body: message}
App.chatrooms=App.cable.subscriptions.create“ChatroomsChannel”,
已连接:->
#当订阅准备在服务器上使用时调用
断开连接:->
#当服务器终止订阅时调用
收到:(数据)->
活动聊天室=$(“[data behavior='messages'][data chatroom id='{data.chatroom.id}']))
如果活动_chatroom.length>0
console.log“聊天室处于活动状态”
活动聊天室。附加(“
#{data.body}
")
调试器
其他的
console.log“聊天室未激活”
$(“[data behavior='chatroom-link'][data chatroom id='{data.chatroom.id}']”).css(“字体重量”,“粗体”)
聊天室\u id=data.chatroom.id
$('tbody')。附加(“”)
$messages=$(“#messages”)
$messages.scrollTop$messages.prop('scrollHeight')
发言:(聊天室号码,留言)->
@执行'speak',{chatroom_id:chatroom_id,body:message}
“聊天室未激活”
这是打字错误吗?你应该转义字符串。是的,我最初是用我的语言写的,所以我把它改成了英语,只是举个例子