Receiving "Uncaught TypeError: start.getTime is not a function" despite Fiddle working

Receiving "Uncaught TypeError: start.getTime is not a function" despite Fiddle working

我有一个名为 myDataset:

的全局变量
var myDataset = {
    "classes":[
        [
            {
                "name":"ECEC 301 Advanced Programming for Engineers Lecture",
                "days":"MWF",
                "times":"02:00 pm - 03:20 pm",
                "crn":"11215"
            },
            {
                "name":"ECEC 301 Advanced Programming for Engineers Lab",
                "days":"W",
                "times":"09:00 am - 10:50 am",
                "crn":"11216"
            }
        ],
        [
            {
                "name":"ECEC 301 Advanced Programming for Engineers Lecture",
                "days":"MWF",
                "times":"02:00 pm - 03:20 pm",
                "crn":"11215"
            },
            {
                "name":"ECEC 301 Advanced Programming for Engineers Lab",
                "days":"F",
                "times":"02:00 pm - 03:50 pm",
                "crn":"11217"
            }
        ]
    ]
};

紧接着,我初始化我的 fullCalendar object:

    $('#calendar').fullCalendar({
        editable: false,
        weekMode: 'liquid',
        handleWindowResize: true,
        weekends: false, // Hide weekends
        defaultView: 'agendaWeek', // Only show week view
        header: false, // Hide buttons/titles
        minTime: '07:00:00', // Start time for the calendar
        columnFormat: {
            week: 'dddd' // Only show day of the week names
        }
    });

我正在使用 addEventSource 覆盖默认行为:

    $('#calendar').fullCalendar( 'addEventSource',
        function(start, end, callback) {
            // When requested, dynamically generate virtual
            // events for every monday and wednesday.
            var events = [];

            for (loop = start.getTime();
                 loop <= end.getTime();
                 loop = loop + (24 * 60 * 60 * 1000)) {
                var test_date = new Date(loop);
                var classes = myDataset.classes;
                for(i = 0; i < classes.length; i++){

                    var obj = classes[i];
                    for(j=0; j < obj.length; j++){

                        var days = obj[j].days;
                        var daysArray = days.split('');

                        for(k =0; k < daysArray.length; k++){

                            if(daysArray[k] == 'M' && test_date.is().monday()){
                                events.push({
                                    title: obj[j].name,
                                    start: $.fullCalendar.formatDate( test_date,  'yyyy-MM-dd HH:mm:ss')
                                });
                            }
                            else if(daysArray[k] == 'T' && test_date.is().tuesday()){
                                events.push({
                                    title: obj[j].name,
                                    start: $.fullCalendar.formatDate( test_date,  'yyyy-MM-dd HH:mm:ss')
                                });
                            }
                            else if(daysArray[k] == 'W' && test_date.is().wednesday()){
                                events.push({
                                    title: obj[j].name,
                                    start: $.fullCalendar.formatDate( test_date,  'yyyy-MM-dd HH:mm:ss')
                                });
                            }
                            else if(daysArray[k] == 'R' && test_date.is().thursday()){
                                events.push({
                                    title: obj[j].name,
                                    start: $.fullCalendar.formatDate( test_date,  'yyyy-MM-dd HH:mm:ss')
                                });
                            }
                            else if(daysArray[k] == 'F' && test_date.is().friday()){
                                events.push({
                                    title: obj[j].name,
                                    start: $.fullCalendar.formatDate( test_date,  'yyyy-MM-dd HH:mm:ss')
                                });
                            }
                        }
                    }

                }
            }
            // return events generated
            callback( events );
        }
    );

但是,当我加载页面时,出现以下错误:

Uncaught TypeError: start.getTime is not a function

此错误出现在 addEventSource 中我的代码片段的第三部分。

在我的 HTML 页面的 header 上,我有以下内容:

<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>

我也试过把它放在下面。

最后,我也在Chrome Dev Tools中检查了我的Sources,库确实加载了。

奇怪的是..我的Fiddle工作:http://jsfiddle.net/h9cC6/2088/

编辑:

start 的输出:

编辑 2:

看起来 Fiddle 使用的是日期 object,但我的代码使用的是时刻 object..

如果您的代码使用的是 moment 对象,但您想使用 date 对象,则需要稍微调整一下代码,来自:

 for (loop = start.getTime();
             loop <= end.getTime();
             loop = loop + (24 * 60 * 60 * 1000)) {

收件人:

for (loop = start._d.getTime();
             loop <= end._d.getTime();
             loop = loop + (24 * 60 * 60 * 1000)) {

使用toDate方法:http://momentjs.com/docs/#/displaying/as-javascript-date/

for (loop = start.toDate().getTime();
             loop <= end.toDate().getTime();
             loop = loop + (24 * 60 * 60 * 1000)) {

更新答案

我刚刚更新了您的 fiddle 以使用 fullcallendar 2.4.0 并调整了您的代码:

工作fiddle:http://jsfiddle.net/robertrozas/h9cC6/2090/