首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSON turbolinks错误

JSON turbolinks错误
EN

Stack Overflow用户
提问于 2017-05-25 21:07:29
回答 1查看 51关注 0票数 1

我正在尝试按照GoRails教程构建一个通知系统。为此,他们使用了一个json文件,我很好地管理了这个文件。

在json文件中有这一行以针对html元素之前,所有操作都很好:

代码语言:javascript
复制
"<a class="dropdown-item" href='#{notification.url}'>#{notification.content.title}</a>"

巫婆正在给我制造关于涡轮机=> 误差图的错误

因此,如果你有任何建议来处理这件事,这将对我很有帮助!

我的代码=

Notification.coffee (哪里是错误):

代码语言:javascript
复制
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 Notifications

Nav-酒吧意见:

代码语言:javascript
复制
<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文件:

代码语言:javascript
复制
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 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-25 22:48:26

检查ahandleSuccess中的类:您是双引用而不是单引号。

享受这张脸!:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44189844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档