在此tutorial
我几乎可以理解。
但是只有一部分我不能。
//javascripts/channels/rooms.coffee
App.global_chat = App.cable.subscriptions.create {
channel: "ChatRoomsChannel"
chat_room_id: ''
},
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) ->
# Data received
send_message: (message, chat_room_id) ->
@perform 'send_message', message: message, chat_room_id: chat_room_id
具有内容send_message
的方法@perform 'send_message', message: message, chat_room_id: chat_room_id
。将其显示为Javascript:
function(message){
return this.perform('speak', {
message: message
});
}
我的问题是表演的功能在哪里?
我试图将@perform
修改为@performs
,但该功能无法正常工作。
答案 0 :(得分:1)
class ActionCable.Subscription
constructor: (@consumer, params = {}, mixin) ->
@identifier = JSON.stringify(params)
extend(this, mixin)
# Perform a channel action with the optional data passed as an attribute
perform: (action, data = {}) ->
data.action = action
@send(data)
从App.cable.subscriptions.create
获得的对象将具有此方法/功能。