用weekNumberCalculation函数显示React FullCalendar

问题描述

我希望将一个函数传递给FullCalendar的weekNumberCalculation选项。谁能给我一个例子,怎么做?

我在文档中读到,该函数必须接受Date,但是我不确定此处需要传递哪个Date值。只是有约会吗?

解决方法

这是一个回调函数。您提供了函数的定义,但是实际上将执行完整的Calendar的代码。这样做时,fullCalendar将传递一个相关的日期。

您永远不会从您自己的代码中调用该函数,因此不必担心。您需要做的就是让函数处理该日期,并将合适的星期数返回给fullCalendar。

因此,您只需在fullCalendar选项中编写如下内容:

weekNumberCalculation: function(date) {
  //here you would do some calculations,making use of the date supplied by fullCalendar....
  return 1; //return a week number (obviously in reality this will be the result of your calculations)
}