简体   繁体   English

单击上一个/下一个如何创建事件? 全日历

[英]How do I create an event upon click prev/next? FullCalendar

So far I have, clicking a day on the calendar in month view, will change the view to agendaDay which does a for loop to populate each time slot with an event. 到目前为止,我已经在月视图中单击日历上的一天,将视图更改为议程日,该日将执行for循环以在每个时隙中填充事件。 I want to do the same thing when I click prev or next. 当我单击上一个或下一个时,我想做同样的事情。 This is my attempt but it keeps crashing when I click prev. 这是我的尝试,但是单击prev时,它始终崩溃。 This part of the code is in fullcalendar.js 这部分代码在fullcalendar.js中

function prev() {
    date = currentView.computePrevDate(date);
    var myCalendar = $('myCalendar1');
    var yearClicked = date.format('YYYY');
    var yearClicked = parseInt(yearClicked);
    var monthClicked = date.format('MM');
    var monthClicked = parseInt(monthClicked) - 1;
    var dayClicked = date.format('DD');
    var dayClicked = parseInt(dayClicked);
    for(timeIncrement = 7; timeIncrement < 23; timeIncrement++){
        alert(date.format('MM'));
        var myEvent = {
            title: 'Rooms Available [' + 11 + ']',
            start: new Date(yearClicked, monthClicked, dayClick, timeIncrement),
            url: 'http://google.com'

        };
        myCalendar.fullCalendar('renderEvent', myEvent);

    }
    renderView();

}

Possibly (it is very hard to tell without more context and code) the fact that you are creating timeIncrement and date as global variables (by not declaring them with var (or let in ES2015)) is an issue. 可能 (很难在没有更多上下文和代码的情况下告诉您)您正在将timeIncrementdate创建为全局变量(通过不使用var声明(或在ES2015中使用它们))是一个问题。

(You may well have explicitly declared date in some outer function, but that is not visible in your example, so I can only go on what I can see) (您可能已经在某些外部函数中显式声明了date ,但是在您的示例中这是不可见的,所以我只能继续看一下)

This may be causing conflicts with other parts of your code... 这可能会导致与代码其他部分的冲突...

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

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