You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FullCalendar单个事件源返回false而非空数组时出现渲染异常及视图切换失效问题求助

FullCalendar单个事件源返回false而非空数组时出现渲染异常及视图切换失效问题求助

我在使用FullCalendar时配置了两个事件源,它们指向同一个URL但携带不同的extraParams参数。

当两个事件源在当前显示的月份都有事件时,一切正常工作。但如果其中一个源在当前月份没有事件,对应的URL返回的不是空数组,而是false,此时日历只会显示一个高亮当前日期的空白界面,而且无法切换到其他月份、周或年视图——另一个返回事件数组的源里的事件也完全没有渲染出来。

在浏览器控制台里我看到了这个错误:Uncaught (in promise) TypeError: e is not iterable.

以下是我的代码:

document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
      headerToolbar: { center: 'dayGridMonth,timeGridWeek,multiMonthYear,listWeek'},
      initialView: 'dayGridMonth',
      themeSystem: 'bootstrap',
      locale: 'de',
      height: 'parent',
      weekNumberCalculation: 'ISO',
      buttonText: {
        today:    'Heute',
        month:    'Monat',
        week:     'Woche',
        year:     'Jahr',
        list:     'Liste'
      },
      eventClick: function(event) {
          if (event.event.url) {
            event.jsEvent.preventDefault();
            window.open(event.event.url, "_blank");
          }
      },
      eventSources: [
        {
            url: 'https://example.com/data/get_events_json.php',
            extraParams: {
                region: 'S',
            },
            failure: function() {
                alert('there was an error while fetching events!');
            },
            color: 'SandyBrown',
            textColor: 'black',
        },
        {
            url: 'https://example.com/data/get_events_json.php',
            extraParams: {
                region: 'N',
            },
            failure: function() {
                alert('there was an error while fetching events!');
            },
            color: 'DarkKhaki',
            textColor: 'black',
        }
      ]
    });
    calendar.render();
  }); 

备注:内容来源于stack exchange,提问作者geom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:18:06