FullCalendar视图更改时执行操作

7
我需要在视图更改时进行某些操作。例如,从月视图更改到agendaDay视图。 没有任何工作想法。有什么建议吗?
viewRender:(function() {

                var lastViewName;
                return function(view) {

                    var view = $('#calendar').fullCalendar('getView');
                    alert('The new title of the view is ' + view.title);
                }
            }),

并且

viewRender:(function(view) {
                var view = $('#calendar').fullCalendar('getView');
                alert('The new title of the view is ' + view.title);
            }),
4个回答

9

1
这在v6中仍然有效。 - Bernesto

4

正如@Willow所指出的,接受的答案在5x版本中不起作用。

viewRendereventAfterAllRenderdatesRender都已过时并在5版中失效。以下是我发现的一些FullCalendar文档,列出了每个版本的破坏性更改。

DatesSet是要使用的属性。来自5版文档的屏幕截图: enter image description here

以您的代码示例为例,下面的代码对我有效。如果有其他人也能受益,可以参考以下内容。

// version 5.11.0 based code
document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    ...
    datesSet: function (dateInfo) {
        var view = dateInfo.view;
        alert('The new title of the view is ' + view.title);
    },
    ...
  });

  calendar.render();
});


3

代码中有小错误。你希望括号内的函数返回另一个函数,但它没有运行。正确的形式是:

(function() {
    return function(){...};
})(); //extra parentheses run the function

这被称为自执行匿名函数


当您执行以下操作时,您的代码将起作用:

viewRender: (function () {
    var lastViewName;
    return function (view) {
        var view = $('#calendar').fullCalendar('getView');
        alert('The new title of the view is ' + view.title);
    }
})(),

1

有点晚了,但还是试一下:

eventAfterAllRender: (function (view) {

// your code

}),


1
此函数已自v4版本起被弃用。 - Ellisan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接