【问题标题】:fullcalendar title range is wrong in new version for the week view周视图的新版本中的完整日历标题范围错误
【发布时间】:2017-01-12 02:49:47
【问题描述】:

我正在为我的项目使用最新版本的完整日历。 3.1.0 我注意到我在这里尝试完成的工作实际上曾经有效,但后来在版本 2 中被破坏了。. 某种形式。 请查看这些小提琴进行比较。

旧版本:

Fiddle that works

新版本:

Fiddle that doesn't work

上面的两个小提琴都使用这种类型的代码来设置标题:

$('#calendar').fullCalendar({
    defaultView: 'basicWeek',
    header: {
        left: 'prev,next today',
        center: 'title',
        right: ''
    },       
    editable: true,
    weekends:false,

请注意,在工作中,标题会根据日期正确调整,其中没有工作的仍然列出周六和周日范围 你能告诉我这些变化是什么以及为什么它被破坏了吗? 我认为他们正在努力修复,但我现在能做些什么来修复代码吗?

【问题讨论】:

标签: javascript fullcalendar title


【解决方案1】:

试试这个:

$('#calendar').fullCalendar({
  defaultDate: moment(),
  header: {
    left: 'prev,next today',
    center: 'title',
    right: ''
  },
  defaultView: 'basicWeek',
  weekends: false,
  eventAfterAllRender: function(view) {
    var firstDate = moment($('th.fc-day-header:first').data("date"));
    var lastDate = moment($('th.fc-day-header:last').data("date"));
    if (firstDate.month() == lastDate.month()) {
      $('.fc-center').find('h2').html(firstDate.format('MMM') + ' ' + firstDate.format('D') + ' - ' + lastDate.format('D') + ', ' + firstDate.format('YYYY'));
    } else {
    //logic to show title for dates with different months / years
      $('.fc-center').find('h2').html('');
    }
  }
});

Fiddle

【讨论】:

  • 谢谢你,我更新了你的小提琴以满足我的需要。我需要标题在下一个和上一个按钮之间,并且看起来像 1/9/2017 - 1/13/2017 格式明智的..我确实注意到了一个问题。 Fiddle 如果您导航到有月份变化的周,那么如果同一周有 1/31 和 2/1 等,它不会在按钮之间显示标题
  • 嗨@coder。如果开始日期和结束日期在不同的月份/年份,您必须自己实施。我只给了你一些工作;)实际上需要 3 种格式:2017 年 12 月 24 日 - 30 日 或 2017 年 4 月 30 日 - 5 月 6 日 或 12 月2017 年 31 月 31 日 - 2018 年 1 月 6 日
  • 没问题,我让它按照我需要的方式工作。那太好了。我很想知道你是否知道我上一篇文章的答案:question
猜你喜欢
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
相关资源
最近更新 更多