Ruby on Rails [基本]客户端(脚本)
示例
app/assets/javascripts/channels/notifications.coffee
App.notifications = App.cable.subscriptions.create "NotificationsChannel",
connected: ->
#当订阅准备好在服务器上使用时调用
$(document).on "change", "input", (e)=>
@notify(e.target.value)
disconnected: ->
#服务器终止订阅时调用
$(document).off "change", "input"
received: (data) ->
#当此通道的网络套接字中有传入数据时调用
$('body').append(data)
notify: (data)->
@perform('notify', data: data)app/assets/javascripts/application.js#通常是这样生成的
//=需要jQuery //=需要jQuery_ujs //=需要Turbolinks //=require_tree。
app/assets/javascripts/cable.js#通常是这样生成的
//=需要action_cable
//=require_self
//=require_tree。/channels
(function() {
this.App|| (this.App = {});
App.cable= ActionCable.createConsumer();
}).call(this);
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西