i want to know what is the first day and the last day of the main month viewed in fullcalendar.
我想知道在fullcalendar中查看的主月的第一天和最后一天是什么。
here is the relevant month view:
这是相关的月份视图:
events: function (start, end, timezone, callback) { //custom events function to be called every time the view changes
alert (start.format());
alert (end.format());
},
when i run this code on this month (april 2017), i get: start.format()=2017-03-26 end.format()= 2017-05-07 and i would like to get the following dates: start: 2017-04-01 end: 2017-04-30
当我在这个月(2017年4月)运行此代码时,我得到:start.format()= 2017-03-26 end.format()= 2017-05-07我希望得到以下日期:开始: 2017-04-01结束:2017-04-30
is there any way for me to get this dates inside the event function?
我有什么方法可以在事件功能中获取这些日期吗?
many thanks
p.s
i would not like to use the "showNonCurrentDates: false" option
我不想使用“showNonCurrentDates:false”选项
2 个解决方案
#1
6
There's no direct way to get this value via the "events" callback, but you can use a slightly kludgy workaround:
没有直接的方法可以通过“事件”回调获得此值,但您可以使用稍微笨重的解决方法:
The viewRender callback gives you access to the "view" object of the current view, which contains the intervalStart
and intervalEnd
properties (see https://fullcalendar.io/docs/views/View_Object/) which relate to the interval the view is trying to represent. In a month view, this will be the start and end of the month. If you capture these into variables with a higher scope than your calendar, you can then re-use them in the events and/or eventsAfterAllRender callbacks, as needed.
viewRender回调使您可以访问当前视图的“视图”对象,该对象包含与视图尝试的间隔相关的intervalStart和intervalEnd属性(请参阅https://fullcalendar.io/docs/views/View_Object/)。代表。在月份视图中,这将是月份的开始和结束。如果将这些变量捕获到范围高于日历的变量中,则可以根据需要在事件和/或eventsAfterAllRender回调中重复使用它们。
var intervalStart, intervalEnd; //variables with higher scope level
$('#calendar').fullCalendar({
//...your options here...
viewRender: function (view, element)
{
intervalStart = view.intervalStart;
intervalEnd = view.intervalEnd;
},
events: function(start, end, timezone, callback) {
console.log(intervalStart.format("YYYY-MM-DD"));
console.log(intervalEnd.format("YYYY-MM-DD"));
//...etc
}
});
Note that intervalEnd
is exclusive, so if the month is April, the intervalEnd
will be given as 1st May.
请注意,intervalEnd是独占的,因此如果月份是4月,则intervalEnd将被指定为5月1日。
Having demonstrated that though, it seems neater just to use the built-in showNonCurrentDates:false
option, as in your earlier question.
虽然已经证明了这一点,但似乎只需要使用内置的showNonCurrentDates:false选项,就像你之前的问题一样。
#2
1
Add this setting showNonCurrentDates: false,
. With this setting, dates that do not belong to the current month will not be shown. From you event callbacks the first day of the current month and the first day of the next month will be shown as the start
and end
respectively
添加此设置showNonCurrentDates:false,。使用此设置,将不会显示不属于当前月份的日期。从您的事件回调当前月的第一天和下个月的第一天将分别显示为开始和结束
$('#calendarLoansByRequestDate').fullCalendar({
// Other settings
showNonCurrentDates: false,
events: function (start, end, timezone, callback) { //custom events function to be called every time the view changes
alert(start.format());
alert(end.format());
}
});
#1
6
There's no direct way to get this value via the "events" callback, but you can use a slightly kludgy workaround:
没有直接的方法可以通过“事件”回调获得此值,但您可以使用稍微笨重的解决方法:
The viewRender callback gives you access to the "view" object of the current view, which contains the intervalStart
and intervalEnd
properties (see https://fullcalendar.io/docs/views/View_Object/) which relate to the interval the view is trying to represent. In a month view, this will be the start and end of the month. If you capture these into variables with a higher scope than your calendar, you can then re-use them in the events and/or eventsAfterAllRender callbacks, as needed.
viewRender回调使您可以访问当前视图的“视图”对象,该对象包含与视图尝试的间隔相关的intervalStart和intervalEnd属性(请参阅https://fullcalendar.io/docs/views/View_Object/)。代表。在月份视图中,这将是月份的开始和结束。如果将这些变量捕获到范围高于日历的变量中,则可以根据需要在事件和/或eventsAfterAllRender回调中重复使用它们。
var intervalStart, intervalEnd; //variables with higher scope level
$('#calendar').fullCalendar({
//...your options here...
viewRender: function (view, element)
{
intervalStart = view.intervalStart;
intervalEnd = view.intervalEnd;
},
events: function(start, end, timezone, callback) {
console.log(intervalStart.format("YYYY-MM-DD"));
console.log(intervalEnd.format("YYYY-MM-DD"));
//...etc
}
});
Note that intervalEnd
is exclusive, so if the month is April, the intervalEnd
will be given as 1st May.
请注意,intervalEnd是独占的,因此如果月份是4月,则intervalEnd将被指定为5月1日。
Having demonstrated that though, it seems neater just to use the built-in showNonCurrentDates:false
option, as in your earlier question.
虽然已经证明了这一点,但似乎只需要使用内置的showNonCurrentDates:false选项,就像你之前的问题一样。
#2
1
Add this setting showNonCurrentDates: false,
. With this setting, dates that do not belong to the current month will not be shown. From you event callbacks the first day of the current month and the first day of the next month will be shown as the start
and end
respectively
添加此设置showNonCurrentDates:false,。使用此设置,将不会显示不属于当前月份的日期。从您的事件回调当前月的第一天和下个月的第一天将分别显示为开始和结束
$('#calendarLoansByRequestDate').fullCalendar({
// Other settings
showNonCurrentDates: false,
events: function (start, end, timezone, callback) { //custom events function to be called every time the view changes
alert(start.format());
alert(end.format());
}
});