简体   繁体   English

使用自定义上一个和下一个按钮 (FullCalendar)

[英]Using custom prev and next buttons (FullCalendar)

My goal is to have 2 custom buttons to jump 1 week back and forth and another 2 buttons to jump 1 month back and forth.我的目标是有 2 个自定义按钮来回跳跃 1 周,另外 2 个按钮来回跳跃 1 个月。 In contrary to the build-in prev and next buttons of FullCalendar, my buttons are supposed not to change with the duration of the view.与 FullCalendar 的内置 prev 和 next 按钮相反,我的按钮应该不会随着视图的持续时间而改变。 I am stuck with the syntax here, calendar.incrementDate( moment.duration(-1, 'week') ) brings up Uncaught TypeError: e is null in browser.我在这里的语法被卡住了, calendar.incrementDate( moment.duration(-1, 'week') )在浏览器中显示Uncaught TypeError: e is null moment.js seems to work fine though. moment.js似乎工作正常。 My code:我的代码:

(...)
      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
      ],
(...)

...and two more questions: ...还有两个问题:

  1. Is there a way not to use moment.js for this?有没有办法不为此使用 moment.js?
  2. What is the best way to change the font size / add some custom CSS for a certain custom button (not for all buttons)?更改字体大小/为某个自定义按钮(不是所有按钮)添加一些自定义 CSS 的最佳方法是什么?

With the hint from ADyson I've found the solution:在 ADyson 的提示下,我找到了解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM