简体   繁体   English

未在完整日历中显示的事件

[英]Events not displayed in full calendar

I've been trying to display some events with fullcalendar but it's not working.我一直在尝试使用 fullcalendar 显示一些事件,但它不起作用。 I've been googling and trying different values but it never worked.我一直在谷歌搜索并尝试不同的值,但它从未奏效。 For example I tried this:例如我试过这个:

                                events: [
                                {
                                    title  : 'event1',
                                    start  : '2020-04-01'
                                },
                                {
                                    title  : 'event2',
                                    start  : '2020-04-05',
                                    end    : '2020-04-07'
                                },
                                {
                                    title  : 'event3',
                                    start  : '2020-04-03T12:30:00',
                                    allDay : false // will make the time show
                                }
                            ],

and also this:还有这个:

                                events: [
                                {"id":"1","start":"2020-04-14T13:00:00","end":"2020-04-14T1‌​6:00:00","title":"Pe‌​r Hour: 11.00,Per Mile: 11.00"},
                                {"id":"2","start":"2020-04-15T13:00:00","end":"2020-04-15T16‌​:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"},
                                {"id":"3","start":"2020-04-16T13:00:00","end":"2020-04-16T16‌​:00:00","title":"Per Hour: 11.00,Per Mile: 11.00"}
                            ]

among other tests.在其他测试中。 All of the values that I tested were found on internet, from people sharing their experience, but for me none of them worked.我测试的所有价值观都是在互联网上找到的,来自人们分享他们的经验,但对我来说,他们都没有奏效。

Any idea of what's wrong with these values?知道这些值有什么问题吗?

Then I'll write the script that will retrive the data from my db but first I have to make it work with hard-coded values.然后我将编写将从我的数据库中检索数据的脚本,但首先我必须使其与硬编码值一起工作。


I'll try to be clearer: I copied / pasted this code from full calendar demo and it's working fine, displaying events correctly:我会尽量清楚一点:我从完整的日历演示中复制/粘贴了这段代码,它工作正常,正确显示事件:

document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');

var calendar = new FullCalendar.Calendar(calendarEl, {
    schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
  plugins: [ 'resourceTimeGrid' ],
  timeZone: 'UTC',
  defaultView: 'resourceTimeGridFourDay',
  datesAboveResources: true,
  header: {
    left: 'prev,next',
    center: 'title',
    right: 'resourceTimeGridDay,resourceTimeGridFourDay'
  },
  views: {
    resourceTimeGridFourDay: {
      type: 'resourceTimeGrid',
      duration: { days: 4 },
      buttonText: '4 days'
    }
  },
  resources: [
    { id: 'a', title: 'Room A' },
    { id: 'b', title: 'Room B' }
  ],
  events: 'https://fullcalendar.io/demo-events.json?with-resources=2'
});

calendar.render();  });

Then I commented the line that was retrieving the events from fullcalendar website and added my own hard-coded events, like this:然后我评论了从 fullcalendar 网站检索事件的行,并添加了我自己的硬编码事件,如下所示:

document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');

var calendar = new FullCalendar.Calendar(calendarEl, {
    schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
  plugins: [ 'resourceTimeGrid' ],
  timeZone: 'UTC',
  defaultView: 'resourceTimeGridFourDay',
  datesAboveResources: true,
  header: {
    left: 'prev,next',
    center: 'title',
    right: 'resourceTimeGridDay,resourceTimeGridFourDay'
  },
  views: {
    resourceTimeGridFourDay: {
      type: 'resourceTimeGrid',
      duration: { days: 4 },
      buttonText: '4 days'
    }
  },
  resources: [
    { id: 'a', title: 'Room A' },
    { id: 'b', title: 'Room B' }
  ],
  //events: 'https://fullcalendar.io/demo-events.json?with-resources=2'
  events: [
                            {
                                title  : 'event1',
                                start  : '2020-04-01'
                            },
                            {
                                title  : 'event2',
                                start  : '2020-04-05',
                                end    : '2020-04-07'
                            },
                            {
                                title  : 'event3',
                                start  : '2020-04-03T12:30:00',
                                allDay : false // will make the time show
                            }
    ]
});

calendar.render();  });

And when I do so, the events are not displayed.当我这样做时,不会显示事件。

Thanks for the edit.感谢您的编辑。

The reason is clearer now - you're using resource-enabled views, but your events don't have any matching resource IDs.原因现在更清楚了 - 您正在使用启用资源的视图,但您的事件没有任何匹配的资源 ID。 So how is fullCalendar supposed to know which resource to place them on, do you think?那么 fullCalendar 应该如何知道将它们放置在哪个资源上,你认为呢? It cannot decide, which means it can't display the events.它无法决定,这意味着它无法显示事件。

You can assign your events to different resources, depending on where they belong.您可以将事件分配给不同的资源,具体取决于它们所属的位置。 Like this, for example:像这样,例如:

events: [
  {
    title  : 'event1',
    start  : '2020-04-01',
    resourceId: 'b'
  },
  {
    title  : 'event2',
    start  : '2020-04-05',
    end    : '2020-04-07',
    resourceId: 'a'
  },
  {
    title  : 'event3',
    start  : '2020-04-03T12:30:00',
    allDay : false, // will make the time show
    resourceIds: ['a', 'b']
  }
]

Demo: https://codepen.io/ADyson82/pen/LYVoZvK?editable=true&editors=001演示: https://codepen.io/ADyson82/pen/LYVoZvK?editable=true&editors=001

Here is the relevant fullCalendar documentation page: Associating Events with Resources这是相关的 fullCalendar 文档页面: Associating Events with Resources

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

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