首页 > 解决方案 > Fullcalendar js事件颜色为json

问题描述

我正在使用 fullcalendar,并且能够显示来自带有 rails 的 json 流的事件。 https://fullcalendar.io/docs/events-json-feed

现在我想设置特定事件的颜色,如示例中所示。我在 json 中指定它,如下所示:

[{"id"=>101, "style"=>"Phone Call", "location"=>"", "created_at"=>Tue, 26 May 2020 14:31:08 UTC +00:00, "updated_at"=>Tue, 26 May 2020 15:17:48 UTC +00:00, "summary"=>"test", "organizer"=>"somePerson", "job_id"=>194, "start"=>Mon, 27 Jan 2020 18:00:00 UTC +00:00, "title"=>"test", "contacts"=>[], "eventColor="=>"#06fff7"}]

请注意,“eventColor="=>"#06fff7" 已设置。

但是,它始终以相同的颜色显示所有事件……而不是指定的事件。

是否可以使用 json 流设置事件颜色?

我玩过不同的选项,例如使用 colro、backgroundColor 等。我使用了十六进制值或颜色名称(例如“黄色”)。

没有成功。我真的不明白我做错了什么。

任何帮助表示赞赏。

=== 更新 ===

这是浏览器接收到的json:

eventColor: "yellow"
contacts: []
created_at: "2020-05-26T14:31:08.663Z"
id: 102
location: ""
organizer: "som eperson "
start: "2020-01-27T18:00:00.000Z"
style: null
summary: "test"
title: "test"
updated_at: "2020-05-26T14:31:08.738Z"

信息显示正确。但是,无法识别颜色。

我正在像这样初始化日历:

var calendar = new Calendar(calendarEl, {
    header: { center: 'dayGridMonth,timeGridWeek,listMonth' },
    plugins: [ listPlugin, timeGridPlugin, dayGridPlugin, bootstrapPlugin ],
    defaultView: 'dayGridMonth',
    height: 'auto',
    width: 'auto',
    editable: true,
    scrollTime: '08:00:00',
    themeSystem: 'bootstrap',
    events: '/jobs/' + jobId +  '/interviews.json',

    }

我删除了引导主题以查看是否有区别,但没有。

标签: javascriptjsonfullcalendarfullcalendar-5

解决方案


推荐阅读