如何从 Firebase JSON 获取事件到 FullCalendar??? (谷歌网络应用程序)

问题描述 投票:0回答:1

这是我来自 Firebase URL 的 JSON

{"allDay":"","end":"2023-02-01 18:00:00","id":"EV1","start":"2023-02-05 09:00:00","title":"Event 1"}

我尝试从 firebase 直接 URL 中获取它们,比如 https://mydatabase.firebaseio.com/Calendar/Test/EV1.json

但是没有运气,日历没有显示任何东西,我试过事件/事件来源

     const calendarEl = document.getElementById('delivery-calendar')
        const calendar = new FullCalendar.Calendar(calendarEl, {
          initialView: 'dayGridMonth',
          locale: 'th',
          themeSystem: 'bootstrap5',

/*   Just for Testing
            events: [  
    {
        "allDay": "",
        "title": "Test event 2",
        "id": "822",
        "end": "2023-02-01 21:00:00",
        "start": "2023-02-02 16:00:00"
    }
]
*/

 // events: 'https://mydatabase.firebaseio.com/Calendar/Test/EV1.json', // Call it directly ,doesn't work

   eventSources: [
    {
      url: 'https://mydatabase.firebaseio.com/Calendar/Test/EV1.json',
      data: function(url){
                return [url] // because some topic said FullCalendar need Array of object so I try to put bracket on it ,still doesn't work!
      }
    }

    ]
        })
        calendar.render()
javascript firebase google-apps-script fullcalendar
1个回答
0
投票

在你的代码评论中你说

FullCalendar 需要对象数组

...是的,这是正确的。如果您的事件源不提供,那么您可以通过处理 eventSourceSuccess 回调来操纵结构。例如:

eventSourceSuccess: function(content, response) {
  return [content];
}

附言

data: function...
不会做任何事情,因为 事件源对象 没有数据属性。请始终仔细研究文档以了解可能发生的情况。

© www.soinside.com 2019 - 2024. All rights reserved.