我正在尝试按照GoRails教程构建一个通知系统。为此,他们使用了一个json文件,我很好地管理了这个文件。
在json文件中有这一行以针对html元素之前,所有操作都很好:
"<a class="dropdown-item" href='#{notification.url}'>#{notification.content.title}</a>"巫婆正在给我制造关于涡轮机=> 误差图的错误
因此,如果你有任何建议来处理这件事,这将对我很有帮助!
我的代码=
Notification.coffee (哪里是错误):
class Notifications
constructor: ->
@notifications = $("[data-behaviour='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.content.title}</a>"
$("[data-behaviour='notification-items']").html(items)
jQuery ->
new NotificationsNav-酒吧意见:
<li class="dropdown" data-behaviour="notifications">
<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown" id="dropdownMenu1" tata-toggle="dropdown" aria-haspopup="true" aria-expended="false"> <i class="fa fa-bell" aria-hidden="true" style="font-size: 25px;"></i></a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1" data-behaviour="notification-items">
<li class="dropdown-item">
<a href="">Action1</a>
</li>
<li class="dropdown-item">
<a> Action2 </a>
</li>
</ul>
</li>为了获得奖金,json文件:
json.array! @notifications do |notification|
json.id notification.id
json.receiver notification.receiver.pseudo
json.sender notification.sender.pseudo
json.title notification.title
json.content notification.content.title
json.url group_path(notification.content.group, anchor: "post_iter(#{notification.content.id})")
end 发布于 2017-05-25 22:48:26
检查a在handleSuccess中的类:您是双引用而不是单引号。
享受这张脸!:)
https://stackoverflow.com/questions/44189844
复制相似问题