使用 weekNumberCalculation 函数显示 React FullCalendar

displaying React FullCalendar with weekNumberCalculation function

我希望将一个函数传递给 FullCalendar 的 weekNumberCalculation 选项。谁能举例说明如何做到这一点?

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

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

您永远不会从自己的代码中调用该函数,因此不必担心。您需要做的就是让您的函数处理该日期和 return 一个合适的周数返回 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)
}