Rails 全日历

Rails fullcalendar

所以当我在 events.js.cofee 的 fullCalendar 脚本中添加事件点击时,它会因 turbolink

而崩溃

语法错误:[stdin]:7:24: reserved word 'function'

<%=javascript_include_tag 'application', 'data-turbolinks-track' => true %>

现在这是我的原始 events.js.coffee 没有添加 eventClick

Note: with this it doesnt crash and works perfectly but my eventClick doesnt do what i want obviously.

$(document).ready ->
$("#calendar").fullCalendar(
       header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,agendaDay'
    },
       events: '/events.json'

)

这是我的 JavascripteventClick:

$(document).ready ->
 $("#calendar").fullCalendar(
       eventClick: function(event) {
            var modal = $("#modal");
            modal.find(".modal-title").html(event.title);
            modal.modal();
          },
       header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,agendaDay'
    },
       events: '/events.json'

)

此代码无效。这是为什么?

Note: In case you need to know what modal is.

<div class="modal" role="dialog" id="modal">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">title</h4>
        </div>
        <div class="modal-body"></div>
        <div class="modal-footer"></div>
    </div>
</div>

问题是函数关键字将您的 js 更改为:

$(document).ready ->
  $("#calendar").fullCalendar
    header:
      left: 'prev,next today',
      center: 'title',
      right: 'month,basicWeek,agendaDay'

    events: '/events.json'
    eventClick: (event, jsEvent) ->
       var modal = $("#modal");
       modal.find(".modal-title").html(event.title);
       modal.modal();
  return

希望对您有所帮助。