0
以下coffeeScript正常运行没有对setUpdateInterval
的引用。通知的设置间隔
class Notifications
constructor: ->
@notifications = $("[data-behavior='notifications']")
@setup() if @notifications.length > 0
setUpdateInterval()
setup: ->
$.ajax(
url: "/notifications.json"
dataType: "JSON"
method: "GET"
success: @handleSuccess
)
handleSuccess: (data) =>
items = $.map data, (notification) ->
"<li class='active'><a href='#{notification.url}'>#{notification.actor} #{notification.notifiable.type}</a></li>"
$("[data-behavior='unread-count']").text(items.length)
$("[data-behavior='notification-items']").html(items)
setUpdateInterval: (notifications) ->
callback = @setup.bind(this)
setInterval(callback, 15000)
jQuery ->
new Notifications
什么是不正确的插入额外的行和集团?
'setUpdateInterval' *在*'handleSuccess'内,所以'handleSuccess'返回'{setUpdateInterval:function ....}'。另外,'setUpdateInterval()'试图调用一个全局函数,'@setUpdateInterval()'会调用该方法(当然如果有这种方法的话)。 –