'GoRails' 之后在我的 rails 应用程序中实施通知
Implementing notifications in my rails app following 'GoRails' tut
我一直在关注通知系统的本教程,在我开始编写 Coffeescript 之前一切都很顺利。这个有问题的脚本是:
class Notifications
constructor: ->
@notifications = $("[data-behavior='notifications']")
@setup() if @notifications.length > 0
setup: ->
$.ajax(
url: "/notifications.json"
dataType: "JSON"
method: "GET"
success: @handleSuccess
)
handleSuccess: (data) =>
items = $.map.data, (notification) ->
"<a class='dropdown-item' href='#{notification.url}>#{notification.action} #{notification.notifiable.type}</a>"
$("[data-behavior='unread-count']").text(items.length)
$("[data-behavior='notification-items']").html(items)
jQuery ->
new Notifications
我得到的错误来自 $.map.data 后面的“,”。当我删除它时,我收到一个新错误,这次在控制台中说:
Uncaught TypeError: $.map.data is not a function
它包括一个视频、带代码的文字记录和一个 GitHub 存储库 link。我认为我的问题与 'data' return 对象有关,而不是数组。
我确定这是一个错字,因为map
是一个函数,而数据是这个函数的参数。所以下面应该是那部分脚本的正确版本:
handleSuccess: (data) =>
items = $.map data, (notification) ->
我一直在关注通知系统的本教程,在我开始编写 Coffeescript 之前一切都很顺利。这个有问题的脚本是:
class Notifications
constructor: ->
@notifications = $("[data-behavior='notifications']")
@setup() if @notifications.length > 0
setup: ->
$.ajax(
url: "/notifications.json"
dataType: "JSON"
method: "GET"
success: @handleSuccess
)
handleSuccess: (data) =>
items = $.map.data, (notification) ->
"<a class='dropdown-item' href='#{notification.url}>#{notification.action} #{notification.notifiable.type}</a>"
$("[data-behavior='unread-count']").text(items.length)
$("[data-behavior='notification-items']").html(items)
jQuery ->
new Notifications
我得到的错误来自 $.map.data 后面的“,”。当我删除它时,我收到一个新错误,这次在控制台中说:
Uncaught TypeError: $.map.data is not a function
它包括一个视频、带代码的文字记录和一个 GitHub 存储库 link。我认为我的问题与 'data' return 对象有关,而不是数组。
我确定这是一个错字,因为map
是一个函数,而数据是这个函数的参数。所以下面应该是那部分脚本的正确版本:
handleSuccess: (data) =>
items = $.map data, (notification) ->