我使用fullcalendar.io插件,并且想在日历的每个单元格中添加一些额外的html,但是在控制台中,我收到以下错误:


Uncaught TypeError: Cannot read property 'append' of undefined
at Calendar.dayRender (mycode.js?v=1.x:31)
at Calendar.publiclyTrigger (main.js?v=1.x:6949)
at DayGrid.DateComponent.publiclyTrigger (main.js?v=1.x:4008)
at DayGrid._renderCells (main.js?v=1.x:796)
at DayGrid.res [as renderCells] (main.js?v=1.x:3189)
at DayGrid.render (main.js?v=1.x:740)
at DayGrid.Component.receiveProps (main.js?v=1.x:3887)
at SimpleDayGrid.render (main.js?v=1.x:1520)
at SimpleDayGrid.Component.receiveProps (main.js?v=1.x:3887)
at DayGridView.render (main.js?v=1.x:1586)



var calendarEl = document.getElementById('calendar');

      var calendar = new FullCalendar.Calendar(calendarEl, {
        plugins: [ 'dayGrid', 'timeGrid', 'list' ],
        defaultView: 'dayGridMonth',//'timeGridWeek',
        header: {
          left: 'prevYear,prev,next,nextYear today',
          center: 'title',
          right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
        },
        defaultDate: '2019-07-12',
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        dayRender: function(date, element) {
          element.append("<input type=\"checkbox\">AM<br>");
        }

      });


我认为出于某种原因,dayRender没有定义elemlement变量。为什么会发生这种情况?

最佳答案

在ADyson建议的Full Calendar v 4.0中,按以下方式使用dayRender:

dayRender: function (dayRenderInfo) {
   dayRenderInfo.el.innerHTML = "<input type=\"checkbox\">AM<br>";
}

关于javascript - Fullcalendar dayRender未定义单元格属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57800882/

10-11 11:15