Jquery 在my rails应用程序中实现以下通知';戈拉尔斯';啧啧
我一直在学习本教程的通知系统,在我开始编写Coffeescript之前,一切都进展顺利。这个脚本是:Jquery 在my rails应用程序中实现以下通知';戈拉尔斯';啧啧,jquery,ruby-on-rails,ajax,coffeescript,Jquery,Ruby On Rails,Ajax,Coffeescript,我一直在学习本教程的通知系统,在我开始编写Coffeescript之前,一切都进展顺利。这个脚本是: class Notifications constructor: -> @notifications = $("[data-behavior='notifications']") @setup() if @notifications.length > 0 setup: -> $.ajax( url: "/notifications.
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
它包括一段视频、带有代码的成绩单和一个GitHub回购链接。我认为我的问题与“数据”返回一个对象有关,而不是数组。我确信这是一个输入错误,因为
map
是一个函数,而数据是这个函数的一个参数。因此,以下应该是该部分脚本的正确版本:
handleSuccess: (data) =>
items = $.map data, (notification) ->
是的,这是正确的。在我看来,我的问题似乎来自于引导。感谢you@iThompkins你可以发布你的问题,除非你能解决它,如果你选择我的答案是正确的,我也会非常感激。谢谢,对不起!
handleSuccess: (data) =>
items = $.map data, (notification) ->