coffeescript java 执行_独立于事件运行的coffeescript函数

我最近在我的rails应用程序中构建了一个通知功能,它来自gorals=>

Here's the tut

这种方法的长短在于创建一个通知模型,该模型记录了参与某个操作的用户之间的关联(即,发布一个帖子将创建一个通知b/t海报和所发布内容的所有者)。

通知还具有一个名为“read”的属性,默认情况下该属性为false。问题从这里开始。当通知保存正确时,只要我以接收通知的用户身份登录,就会向服务器发送post请求,将“read”更改为true。下面是负责发出请求的脚本和视图。

class Notifications

constructor: ->

@notifications = $("[data-behavior='notifications']")

@setup() if @notifications.length > 0

setup: ->

$("[data-behavior='notifications-link']").on "click", @handleClick ->

$.ajax(

url: "/notifications.json"

dataType: "JSON"

method: "GET"

success: @handleSuccess

)

handleClick: (e) =>

$.ajax(

url: "/notifications/mark_as_read"

dataType: "JSON"

method: "POST"

success: ->

$("[data-behavior='unread-count']").text("")

)

handleSuccess: (data) =>

console.log(data)

items = $.map data, (notification) ->

"#{notification.actor} #{notification.action} #{notification.notifiable.type}"

console.log(items)

$("[data-behavior='notification-items']").html(items)

$("[data-behavior='unread-count']").text(items.length)

if items.length is 0

$("[data-behavior='unread-count']").text("")

jQuery ->

new Notifications

以及观点:

从对脚本的修改来看,@handleclick函数似乎是在不发生click事件的情况下自行运行的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值