【问题标题】:FullCalendar-v4 allDay events not renderingFullCalendar-v4 allDay 事件未呈现
【发布时间】:2019-08-07 22:39:25
【问题描述】:

我已经设法让我的定期事件显示在日历上,但我的单个 allDay 事件不会呈现,我认为这是一个字段问题。

我已尝试将活动的开始时间设为 iso 日期,这似乎无关紧要,因为我的重复活动被保存为字符串。

这是一个经常性的事件,并显示在日历上

{
    "_id" : ObjectId("5d4af079f91ff532f8fc0385"),
    "daysOfWeek" : [ 
        1, 
        2, 
        3
    ],
    "locationId" : ObjectId("5d28cad23f49646797e05adc"),
    "allDay" : true,
    "start" : "2019-08-07",
    "end" : "2019-08-07",
    "startRecur" : "2019-08-07",
    "endRecur" : "2019-08-31",
    "title" : "Change Bulbs",
    "backgroundColor" : "rgb(87, 87, 244)",
    "source" : null,
    "interval" : "Weekly",
    "category" : "Facility",
    "monday" : true,
    "tuesday" : true,
    "wednesday" : true,
    "completed" : false,
    "frequency" : null,
    "__v" : 0
}

这是在 FC-v3 中出现但在 v4 中不会出现的单个事件

{
    "_id" : ObjectId("5d4b455e121f726f510f2b5c"),
    "daysOfWeek" : [],
    "batchId" : ObjectId("5d28f52d823083adfc6e8c4d"),
    "locationId" : ObjectId("5d28cad23f49646797e05adc"),
    "end" : null,
    "startRecur" : "",
    "endRecur" : "",
    "allDay" : true,
    "start" : "2019-08-08",
    "title" : "First Transplant",
    "backgroundColor" : "rgb(87, 87, 244)",
    "interval" : "Single Event",
    "category" : "Cultivation",
    "monday" : false,
    "tuesday" : false,
    "wednesday" : false,
    "thursday" : false,
    "friday" : false,
    "saturday" : false,
    "sunday" : false,
    "completed" : false,
    "__v" : 0
}

所以我用正确的 ISO 日期做了一个事件,它也失败了

{
    "_id" : ObjectId("5d4b4f9a56114f747c7ddcef"),
    "daysOfWeek" : [],
    "batchId" : ObjectId("5d28f52d823083adfc6e8c4d"),
    "locationId" : ObjectId("5d28cad23f49646797e05adc"),
    "allDay" : true,
    "start" : ISODate("2019-08-08T00:00:00.000Z"),
    "end" : null,
    "title" : "IMP",
    "backgroundColor" : "rgb(87, 87, 244)",
    "interval" : "Single Event",
    "category" : "Cultivation",
    "monday" : false,
    "tuesday" : false,
    "wednesday" : false,
    "thursday" : false,
    "friday" : false,
    "saturday" : false,
    "sunday" : false,
    "completed" : false,
    "__v" : 0
}

comp.ts 代码

createEvent(form) {
        if (form.valid) {
            this.newEvent.category = 'Cultivation';
            this.newEvent.completed = false;
            this.newEvent.allDay = true;
            this.newEvent.locationId = this.selectedLocation._id;
            this.newEvent.batchId = this.selectedBatch._id;
            this.newEvent.start = moment(this.newEvent.start).utc();
            this.newEvent.start.hours(0).minutes(0).seconds(0);
            // this.newEvent.source =  null;
            // this.newEvent.daysOfWeek = [];
            if (this.newEvent.interval === 'Single Event') {
                this.newEvent.end = null;
                // this.newEvent.startRecur = '';
                // this.newEvent.endRecur = '';
                this.newEvent.monday = false;
                this.newEvent.tuesday = false;
                this.newEvent.wednesday = false;
                this.newEvent.thursday = false;
                this.newEvent.friday = false;
                this.newEvent.saturday = false;
                this.newEvent.sunday = false;
            }
            // if ( this.newEvent.interval === 'Daily'  || this.newEvent.interval === 'Weekly'){
            // }
            if (this.newEvent.interval === 'Weekly') {
                this.newEvent.startRecur = this.newEvent.start;
                this.newEvent.end = this.newEvent.start;
                this.newEvent.frequency = NaN;
                if (this.newEvent.sunday) {
                    this.newEvent.daysOfWeek.push(0);
                }
                if (this.newEvent.monday) {
                    this.newEvent.daysOfWeek.push(1);
                }
                if (this.newEvent.tuesday) {
                    this.newEvent.daysOfWeek.push(2);
                }
                if (this.newEvent.wednesday) {
                    this.newEvent.daysOfWeek.push(3);
                }
                if (this.newEvent.thursday) {
                    this.newEvent.daysOfWeek.push(4);
                }
                if (this.newEvent.friday) {
                    this.newEvent.daysOfWeek.push(5);
                }
                if (this.newEvent.saturday) {
                    this.newEvent.daysOfWeek.push(6);
                }
            }
...sub to database

【问题讨论】:

    标签: javascript typescript fullcalendar fullcalendar-4


    【解决方案1】:

    设置"daysOfWeek" : [], 意味着您告诉日历它不能在一周中的任何一天显示事件。这就是它不会出现的原因。

    不要在代码中为单个事件设置该选项,这样就可以了:

    {
        "_id" : ObjectId("5d4b455e121f726f510f2b5c"),
        "batchId" : ObjectId("5d28f52d823083adfc6e8c4d"),
        "locationId" : ObjectId("5d28cad23f49646797e05adc"),
        "end" : null,
        "startRecur" : "",
        "endRecur" : "",
        "allDay" : true,
        "start" : "2019-08-08",
        "title" : "First Transplant",
        "backgroundColor" : "rgb(87, 87, 244)",
        "interval" : "Single Event",
        "category" : "Cultivation",
        "monday" : false,
        "tuesday" : false,
        "wednesday" : false,
        "thursday" : false,
        "friday" : false,
        "saturday" : false,
        "sunday" : false,
        "completed" : false,
        "__v" : 0
    }
    

    演示:https://codepen.io/ADyson82/pen/LwdgeG

    附:你的日期字符串没有问题。

    【讨论】:

    • 我已将上面的代码复制并粘贴到数据库中,但事件仍未填充。
    • 嗯。如果没有看到你做了什么的工作示例,以及结果究竟是什么数据进入了 fullCalendar,那么我无法告诉你出了什么问题。正如您从我的 CodePen 演示中看到的那样,如果您将这些数据准确地提供给 fullCalendar,而不包括 daysOfWeek 属性,那么它可以正常工作。这个概念是正确的,但您的代码中可能存在其他一些错误,这意味着事件未发送到日历或不包含正确的属性。如果您能提供可重现的完整示例,我可以提供帮助
    • 我发现从文档和模型中删除“daysOfWeek”字段可以让我的单个全天事件正确呈现。不幸的是,对于遇到同样问题并想要使用重复事件的人来说,这不是一个可靠的解决方案。因为 FC 不会为每个重复事件构建单独的对象,所以重复事件功能对我没有用,我必须手动填充这些对象。感谢您的提示。
    • @MVM 我不确定我是否明白您的意思……您可以根据每种情况的需要包含或不包含 daysOfWeek 字段。如果它不会成为重复事件,则不要在您的对象中创建该属性。实现这一点应该不难吧?或者,如果您愿意,您可以切换到使用 RRule 定义重复事件,正如relevant fullCalendar plugin 提供的那样 - 也许这会更适合您?当然,如果您有改进 fullCalendar 这部分的建议,您可以随时向他们发送功能请求。
    • 啊,我的意思是我的解决方案“从文档和模型中删除“daysOfWeek”字段”不是一个可靠的解决方案。感谢您的帮助。
    猜你喜欢
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多