【问题标题】:Using custom prev and next buttons (FullCalendar)使用自定义上一个和下一个按钮 (FullCalendar)
【发布时间】:2020-12-05 18:35:20
【问题描述】:

我的目标是有 2 个自定义按钮来回跳跃 1 周,另外 2 个按钮来回跳跃 1 个月。与 FullCalendar 的内置 prev 和 next 按钮相反,我的按钮应该不会随着视图的持续时间而改变。我被这里的语法困住了,calendar.incrementDate( moment.duration(-1, 'week') ) 在浏览器中显示Uncaught TypeError: e is nullmoment.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
      ],
(...)

...还有两个问题:

  1. 有没有办法不为此使用 moment.js?
  2. 更改字体大小/为某个自定义按钮(不是所有按钮)添加一些自定义 CSS 的最佳方法是什么?

【问题讨论】:

  • 1.是的当然。 fullCalendar 根本不需要 momentJS。事实上fullcalendar.io/docs/Calendar-incrementDate 明确了 incrementDate 函数接受什么作为输入。 fullCalendar 的“Duration”与 momentJS 的 Duration 无关
  • 2.这似乎是一个完全独立的问题,值得一个单独的问题
  • 1.谢谢,请参阅下面的解决方案。 2.我在这里发布了这个问题:stackoverflow.com/questions/65167079/…

标签: javascript fullcalendar momentjs


【解决方案1】:

根据 ADyson 的提示,我找到了解决方案:

      customButtons: {
        prevWeek: {
          text: '<',
          click: function() {
            calendar.changeView( 'resourceTimelineWeek' );
            calendar.incrementDate( { days: -7 } );
          }
        },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 2018-05-04
    • 2020-06-04
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多