简体   繁体   English

FullCalendar对象无法理解对象数组参数

[英]Object array argument isn't being understood by FullCalendar object

I'm populating an object array from an ajax call using jQuery, in order to display event data from our system into the calendar. 我正在使用jQuery从ajax调用中填充对象数组,以便将事件数据从我们的系统显示到日历中。 For some reason, it won't recognize it as events, and they aren't being displayed on the calendar. 由于某种原因,它不会将其识别为事件,也不会在日历上显示它们。 See code below. 请参见下面的代码。

I've checked it over 100 times, and I'm sure the data is coming in the correct format. 我已经检查了100多次,并且确定数据的格式正确。 The events variable is also not empty at runtime. events变量在运行时也不为空。

var events = [];

$.ajax({
        type: 'GET',
        url: "ajax/shared.ashx",
        dataType: 'json',
        data: 'm=get-staff-schedule',
        success: function (json) {
            console.log(json);
            $.each(json.response.data, function (i, app) {
                events.push({
                    id: app.id,
                    title: app.ADMIN_NAME,
                    daysOfWeek: app.day - 1,
                    startTime: app.time_in,
                    endTime: app.time_out
                });

            });
            renderCalendar(events);
        }
    });

function renderCalendar(events) {
        var calendarEl = document.getElementById('calendar');
        var d = new Date();
        var date = d.getFullYear() + '-' + padDigits(d.getMonth() + 1, 2) + '-' + padDigits(d.getDate(), 2)
        debugger
        var calendar = new FullCalendar.Calendar(calendarEl, {
            plugins: ['interaction', 'dayGrid', 'timeGrid', 'bootstrap'],
            themeSystem: 'bootstrap',
            defaultView: 'timeGridWeek',
            defaultDate: date,
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'dayGridMonth,timeGridWeek,timeGridDay'
            },
            events: events
        });

        calendar.render();
    }

Here is the image of the rendered, blank, calendar. 这是渲染的空白日历的图像。 Also, here are FullCalendar's docs for reference: https://fullcalendar.io/docs/event-parsing 另外,以下是FullCalendar的文档供参考: https ://fullcalendar.io/docs/event-parsing

空的

replace 更换

events.push({
                    id: app.id,
                    title: app.ADMIN_NAME,
                    daysOfWeek: app.day - 1,
                    startTime: app.time_in,
                    endTime: app.time_out
                });

by 通过

events.push({
                    id: app.id,
                    title: app.ADMIN_NAME,
                    daysOfWeek: app.day - 1,
                    start: app.time_in,
                    end: app.time_out
                });

I figured it out! 我想到了! Only took me like 2 hours! 只花了我两个小时!

Basically, this object requires all strings. 基本上,此对象需要所有字符串。 So, the daysOfWeek value needed to be converted from an integer to a string. 因此,需要将daysOfWeek值从整数转换为字符串。 Here is what I did: 这是我所做的:

events.push({
   id: app.id,
   title: app.ADMIN_NAME,
   daysOfWeek: (app.day - 1) + '',
   startTime: app.time_in,
   endTime: app.time_out
});

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

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