FullCalendar eventConstraint与eventDataTransform函数

时间:2017-10-05 14:14:11

标签: fullcalendar

我有一个fullCalendar,其中事件数据来自JSON提要。 字段名称与fullCalendar字段名称不匹配,因此我使用eventDataTransform函数,如下所示:

eventDataTransform: function (eventData){
    var ro = new Object();
    ro.start = eventData.myStartField;
    ro.end = eventData.myEndField;
    ro.title = eventData.myTitleField;
    ro.sourceObject = eventData;
    console.log("converted event", ro);
    return ro;
}

我将原始JSON对象保留在自定义字段' sourceObject'。

这很完美。没有问题。 直到我向fullCalendar添加约束:

eventConstraint: {start: "08:00:00", end: "16:00:00"}

从那一刻开始,每当我移动一个事件或改变它的持续时间时,都会触发eventDataTransform函数,并且我的所有事件的开始和结束值都为undefined。 这很奇怪,因为拖动根本不应该触发eventDataTransform函数。 这是一个错误还是我做错了什么?

由于

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel='stylesheet' href='css/fullcalendar.min.css' />
<link href='css/scheduler.min.css' rel='stylesheet' />
<script   src="https://code.jquery.com/jquery-3.2.1.min.js"   integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="   crossorigin="anonymous"></script>
<script src='js/moment.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script src='js/scheduler.min.js'></script>
<script>
$(document).ready(function() {
    console.log("init");
    $('#calendar').fullCalendar({
        schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
        defaultView: 'agendaWeek',
        weekends: false,
        weekNumbers: true,
        allDaySlot: false,
        slotLabelFormat: 'H:mm',
        nowIndicator: true,
        selectable: true,
        defaultDate: '2017-09-12',
        editable: true,
        eventConstraint: {start: "08:00:00", end: "16:00:00"},
        eventDataTransform: function (eventData){
            var ro = new Object();
            ro.start = eventData.myStartField;
            ro.end = eventData.myEndField;
            ro.title = eventData.myTitleField;
            ro.sourceObject = eventData;
            console.log("converted event", ro);
            return ro;
        },
        events: [
            {
                myTitleField: 'Long Event',
                myStartField: '2017-09-07',
                myEndField: '2017-09-10'
            },
            {
                myTitleField: 'Meeting',
                myStartField: '2017-09-12T10:30:00',
                myEndField: '2017-09-12T12:30:00'
            },
            {
                myTitleField: 'Lunch',
                myStartField: '2017-09-12T12:00:00'
            },
            {
                myTitleField: 'Meeting',
                myStartField: '2017-09-12T14:30:00'
            },
            {
                myTitleField: 'Happy Hour',
                myStartField: '2017-09-12T17:30:00'
            }
        ]
    });
});
</script>
</head>
<body>
<div id="calendar" class="container">
</div>
</body>
</html>

0 个答案:

没有答案