我的目标是有 2 个自定义按钮来回跳转 1 周,另外 2 个按钮来回跳转 1 个月。与 FullCalendar 的内置上一个和下一个按钮相反,我的按钮不应该随着 View 的持续时间而改变。我对这里的语法感到困惑, calendar.incrementDate( moment.duration(-1, 'week') )
在浏览器中显示 Uncaught TypeError: e is null
。 moment.js
似乎工作正常。我的代码:
(...)
customButtons: {
prevWeek: {
text: '<',
click: function() {
calendar.changeView( 'resourceTimelineWeek' ), //works
calendar.incrementDate( moment.duration(-1, 'week') ), //error
alert('clicked the prevWeek button!');
}
}
},
headerToolbar: {
center: 'week,month',
right: 'today prevMonth,prevWeek,nextWeek,nextMonth'
},
slotLabelFormat: [
{ month: 'long', year: 'numeric' }, // top level of text
{ week: 'W' },
{ weekday: 'short', day: '2-digit' } // lower level of text
],
(...)
...还有两个问题:
- 有没有办法不使用 moment.js 来实现此目的?
- 为某个自定义按钮(不适用于所有按钮)更改字体大小/添加一些自定义 CSS 的最佳方法是什么?
最佳答案
根据 ADyson 的提示,我找到了解决方案:
customButtons: {
prevWeek: {
text: '<',
click: function() {
calendar.changeView( 'resourceTimelineWeek' );
calendar.incrementDate( { days: -7 } );
}
},
关于javascript - 使用自定义上一个和下一个按钮 (FullCalendar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65160570/