简体   繁体   English

Symfony3 - fullcalendar.js 事件不显示

[英]Symfony3 - fullcalendar.js events not displaying

I'm using fullcalendar.js with Symfony 3.4 (as all the bundles are deprecated since version 3).我在 Symfony 3.4 中使用 fullcalendar.js(因为从版本 3 开始不推荐使用所有包)。 The calendar itself is showing, when I hardcoded in js the events they're showing.日历本身正在显示,当我在 js 中硬编码它们显示的事件时。 But when i send my events with JSON they don't show themselves and the calendar is blank.但是当我用 JSON 发送我的事件时,它们不会显示自己并且日历是空白的。 However, the json source is in the correct format and indeed catched by my page (http 200 response).但是,json 源的格式正确并且确实被我的页面捕获(http 200 响应)。 Here's my controller who got the data and send a JSON:这是我获取数据并发送 JSON 的控制器:

 /**
 * @Route("/calendrierFeed", name="calendrierFeed", methods={"GET"})
 */
public function feedAction()
{
    $em = $this->getDoctrine()->getManager();
    $aquariums = $em->getRepository('AppBundle\Entity\Aquarium')
        ->findBy(
            array('user' => $this->getUser()->getId())
        );
    $events = $em->getRepository('AppBundle\Entity\Calendrier')
        ->findBy(array(
            'aquarium' => $aquariums
        ));

    $calendrier = array();

    foreach ($events as $event) {
        $e = array();
        $e['id'] = $event->getId();
        $e['title'] = $event->getTypeEntretiens() . " pour l'aquarium " . $event->getAquarium()->getNom();
        $e['start'] = $event->getDateEntretiens();
        if ($event->getRealise()) {
            $e['color'] = 'green';
        } else {
            $e['color'] = 'red';
        }
        $e['allDay'] = true;

        array_push($calendrier, $e);
    }
    return $this->json($calendrier);
}

Here's my twig template:这是我的树枝模板:

 {% block stylesheets %} {{ parent() }} <link rel="stylesheet" href="{{ asset('css/membre/fullcalendar.min.css') }}"> {% endblock %} {% block body %} <div id='calendar'></div> {% endblock %} {% block javascripts %} {{ parent() }} <script src="{{ asset('js/membre/moment.min.js') }}"></script> <script src="{{ asset('js/membre/jquery.min.js') }}"></script> <script src="{{ asset('js/membre/fullcalendar.min.js') }}"></script> <script src="{{ asset('js/membre/fr.js') }}"></script> <script type="text/javascript"> $(document).ready(function() { $('#calendar').fullCalendar({ events: '/calendrierFeed', defaultView: 'month', selectable:true, selectHelper:true, editable:true }); }); </script> {% endblock %}

And here's my JSON feed这是我的 JSON 提要

[{"id":2,"title":"oui pour l\u0027aquarium 200L","start":{"date":"2018-02-12 00:00:00.000000","timezone_type":3,"timezone":"UTC"},"color":"red","allDay":true}]

Your date should be a string, not an object.您的日期应该是一个字符串,而不是一个对象。

I checked in my json feed in my personnal project, I got it this way:我在我的个人项目中检查了我的 json 提要,我是这样得到的:

"start":"2018-02-13"

From the doc从文档

The date/time an event begins.事件开始的日期/时间。 Required.必需的。

A Moment-ish input, like an ISO8601 string. Moment-ish 输入,如 ISO8601 字符串。 Throughout the API this will become a real Moment object.在整个 API 中,这将成为一个真正的 Moment 对象。

This mean you should format your date这意味着你应该格式化你的日期

$e['start'] = $event->getDateEntretiens()->format('Y-m-d');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM