【问题标题】:Fullcalendar JSON Encode and LaravelFullcalendar JSON 编码和 Laravel
【发布时间】:2018-11-19 14:14:45
【问题描述】:

我在一个页面上显示了一个日历,但我这辈子都无法让它正常工作。我在我的控制器中创建一个数组,将它传递给视图 json_encoded 但全日历不想拿起数组并将其弹出到日历中。请参阅下面的代码:

HomeController

    public function calendar_feed(){

  return response()->json(
  [
    'title' => 'Matts Booking',
    'start' => '2018-01-01T22:40',
    'end' => '2019-01-01T23:40'
  ], 200
  );

}

全日历功能

<script type="text/javascript">
    (function ( $ ) { 

  $('#calendar').fullCalendar({
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay,listWeek'
    },
    editable: false,
    defaultView: 'agendaWeek',
    firstDay: 1,
    eventLimit: false, // allow "more" link when too many events
    navLinks: true,
    events: '{{ route("calendar_feed") }}'
  });
    }( jQuery ));
</script>

数组发送的内容

{"title":"Matts Booking","start":"2018-01-01T22:40","end":"2019-01-01T23:40"}

任何帮助将不胜感激!

非常感谢

【问题讨论】:

    标签: jquery laravel laravel-5 fullcalendar


    【解决方案1】:

    根据eventsarray example的属性名,貌似需要一个数组,所以多加一对方括号:

    public function calendar_feed(){
      return response()->json([[
          'title' => 'Matts Booking',
          'start' => '2018-01-01T22:40',
          'end' => '2019-01-01T23:40'
       ]], 200
      );
    }
    

    现在您返回一个包含单个元素的对象数组。

    【讨论】:

    • 伊凡,如果我能吻你,我会的!谢谢你,它工作得很好!
    猜你喜欢
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 2016-04-13
    • 2018-11-15
    • 2020-01-16
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多