未捕获的类型错误:回调不是函数 FullCalendar

时间:2021-04-07 20:49:10

标签: javascript jquery fullcalendar

我在尝试将事件放入日历时遇到问题,显示错误:

document.addEventListener("DOMContentLoaded", function () {
  var calendarEl = document.getElementById("calendar");
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: "dayGridMonth",
    events: function (start, end, timezone, callback) {
      jQuery.ajax({
        url: "/getAllCitas",
        type: "GET",
        success: function (doc) {
          var events = [];
          doc.forEach(function (evt) {
            events.push({
              title: evt.paciente,
              start: evt.date,
              end: evt.date,
            });
          });
          console.log(events);
          callback(events);
        },
      });
    },
  });
  calendar.render();
});

错误

Uncaught TypeError: callback is not a function
    at Object.success (citas.js:179)
    at c (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at l (jquery.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery.min.js:2)

事件结果。文档是一个包含更多信息的 json,我只需要事件中的信息。

0: {title: undefined, start: "2021-03-18", end: "2021-03-18"}
1: {title: undefined, start: "2021-04-02", end: "2021-04-02"}
2: {title: undefined, start: "2021-04-02", end: "2021-04-02"}
3: {title: undefined, start: "2021-04-06", end: "2021-04-06"}
4: {title: undefined, start: "2021-04-05", end: "2021-04-05"}
5: {title: "603fd0e423f0d241ecfdd337", start: "2021-04-06", end: "2021-04-06"}
6: {title: "Carlos", start: "2021-04-08", end: "2021-04-08"}

我需要你的帮助,谢谢

1 个答案:

答案 0 :(得分:1)

我得到了解决方案,您所说的回调来自旧版本。现在它的successCallback,我改变了它,现在它可以工作了,这是新代码

document.addEventListener("DOMContentLoaded", function () {
  var calendarEl = document.getElementById("calendar");
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: "dayGridMonth",
    events: function (fetchInfo, successCallback, failureCallback) {
      jQuery.ajax({
        url: "/getAllCitas",
        type: "GET",
        success: function (res) {
          var events = [];
          res.forEach(function (evt) {
            events.push({
              title: evt.paciente,
              start: evt.date,
              end: evt.date,
            });
          });
          successCallback(events);
        },
      });
    },
  });
  calendar.render();
});

谢谢