【问题标题】:FullCalendar not showing events from JSON dataFullCalendar 不显示来自 JSON 数据的事件
【发布时间】:2023-04-04 20:04:01
【问题描述】:

我已将 FullCalendar 控件添加到 Aurelia 项目并显示日历,但未显示来自我的 JSON 源(跨域)的任何事件。

events.js

import { fullCalendar } from 'fullcalendar';

export class Events {
  heading = "Welcome to Events";

  attached() {
    $('#eventscalendar').fullCalendar({
      weekends: false,
      header: {
        left: '',
        center: 'prev title next',
        right: ''
      },
      eventSources: [
        {
          url: 'http://mydomain/pub/api_events_aurelia.php',
          dataType: 'jsonp',
          color: 'yellow',
          textColor: 'black'
        }
      ],
      loading: function (bool) {
        if (bool) $('#loading').show();
        else $('#loading').hide();
      }
    });

  }

  refreshEvents() {
    // reload events
    console.log("refreshing...");
    $('#eventscalendar').fullCalendar('refetchEvents');
  }
}

events.html

<template>
  <require from="fullcalendar/fullcalendar.css"></require>

  <h2 class="text-center">${heading}</h2>

  <!-- bootstrap element for FullCalendar -->
  <button class="btn btn-primary" click.trigger="refreshEvents()">Refresh</button>
  <div class="alert alert-info pull-right" id="loading">Loading...</div>
  <div id="eventscalendar"></div>

</template>

日历加载(在 Aurelia 的 attach() 内置函数中)但不显示任何事件。如果我将事件数据直接粘贴到实例化中(将 eventSources: 更改为 events: 后跟 JSON 数据),它可以工作。

JSON 源正在输出格式正确的 JSON 数据:

JSON 源数据

[{
  "id": "3596",
  "title": "Feriado Local- No hay clases.",
  "start": "2016-11-02",
  "end": "2016-11-02"
}, {
  "id": "3933",
  "title": "Moms In Prayer",
  "start": "2016-11-02T07:30:00",
  "end": "2016-11-02T08:30:00"
}, {
  "id": "3826",
  "title": "Early Release Day",
  "start": "2016-11-02T12:30:00",
  "end": "2016-11-02T13:30:00"
}, {
  "id": "3827",
  "title": "Parent Seminar",
  "start": "2016-11-03",
  "end": "2016-11-03"
}, {
  "id": "3593",
  "title": "Salida Temprano. Reporte de Progreso.",
  "start": "2016-11-03",
  "end": "2016-11-03"
}, {
  "id": "3568",
  "title": "Fiesta \"Ya S\u00e9 Multiplicar\"",
  "start": "2016-11-04",
  "end": "2016-11-04"
}, {
  "id": "3969",
  "title": "Thrive",
  "start": "2016-11-04T18:30:00",
  "end": "2016-11-04T21:00:00"
}, {
  "id": "3949",
  "title": "No classes - Day After Presidential Elections",
  "start": "2016-11-07",
  "end": "2016-11-07"
}, {
  "id": "3594",
  "title": "Entrega de Reporte de Progreso.",
  "start": "2016-11-07",
  "end": "2016-11-07"
}, {
  "id": "3828",
  "title": "Talent Show Auditions",
  "start": "2016-11-08T14:30:00",
  "end": "2016-11-08T16:00:00"
}, {
  "id": "3954",
  "title": "National Honor Society Induction",
  "start": "2016-11-08T18:30:00",
  "end": "2016-11-08T19:30:00"
}, {
  "id": "3600",
  "title": "\u00daltimo Seminario para Padres y Madres del a\u00f1o 2015",
  "start": "2016-11-10",
  "end": "2016-11-10"
}, {
  "id": "3829",
  "title": "Talent Show Auditions",
  "start": "2016-11-10T14:30:00",
  "end": "2016-11-10T16:00:00"
}, {
  "id": "3599",
  "title": "D\u00eda de \u00c9nfasis Espiritual",
  "start": "2016-11-11",
  "end": "2016-11-11"
}]

有没有办法调试FullCalendar的事件数据,看看是否成功加载了json数据?

【问题讨论】:

  • json 似乎有效。你确定你的观点应该有一个事件吗?检查Network 选项卡上的开发人员工具并检查对服务器的请求。你有错误吗?请求是否正确返回了事件列表?如果您复制响应并将其粘贴到 JsonFormater 上,它是有效的 JSON 吗?

标签: fullcalendar


【解决方案1】:

最终,解决方案是改变:

eventSources: [
  {
    url: 'http://mydomain/pub/api_events_aurelia.php',
    dataType: 'jsonp',
    color: 'yellow',
    textColor: 'black'
  }
],

到:

events: 'http://mydomain/pub/api_events_aurelia.php',

我仍然不知道为什么顶部起作用而底部不起作用,但是我的问题已经解决了。

【讨论】:

  • 我只是想让这个东西显示出来,但它失败了“未处理的拒绝类型错误:$(...).fullCalendar 不是一个函数”一个旧的 SO 帖子 (2014) 提到了类似的错误....怀疑是损坏的“..min.js”。所以在我的 aurelia.json 中,我改成了非缩小版;无济于事。我正在使用 3.2.0 的全日历。让我知道您以前遇到过这种情况,如果遇到过,您是怎么做的。
  • 将问题作为一个新问题发布并在此处发布链接,我会看看它。
猜你喜欢
  • 2011-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-25
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多