亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

FullCalendar 不顯示通過帶有動態“extraParams”參數的 JSON 獲取的事件

FullCalendar 不顯示通過帶有動態“extraParams”參數的 JSON 獲取的事件

江戶川亂折騰 2021-12-02 14:52:46
我在使用動態“extraParams”參數顯示通過 JSON 獲取的事件時遇到問題,如文檔中所述:var calendarEl = document.getElementById('calendar');calendar = new FullCalendar.Calendar(calendarEl, {...,events: {    url: '/getEvents',    method: 'POST',    extraParams: function() {        var combobox = document.getElementById('combobox');        var value = combobox.options[combobox.selectedIndex].value;        return {client: value};    },    failure: function(error) {        console.log(error);        alert("Error", "Unable to fetch events", "red");    },},...});calendar.render();在調試面板上,我可以看到 FullCalendar 發出的請求:XHR POST https://127.0.0.1:8443/getEvents有了這個參數:client: Allstart: 2019-09-30T00:00:00Zend: 2019-11-11T00:00:00ZtimeZone: UTC和回應:{  "error": "",   "events": [    {      "allDay": 1,       "color": "blue",       "end": "2019-10-24T00:00:00.000Z",       "extendedProps": {        "company": "Company 1",         "state": "Active",         "type": "task"      },       "groupId": "48",       "id": 27,       "start": "2019-10-23T00:00:00.000Z",       "title": "Title 1",       "url": ""    },     {      "allDay": 1,       "color": "blue",       "end": "2019-11-07T00:00:00.000Z",       "endpoints": 0,       "extendedProps": {        "company": "All",         "description": "Description",         "creationDate": "2019-11-04",         "state": "Active",         "tecnology": "test",         "element": "test 1",         "type": "type 2",         "user": "user 1",         "version": "1.2"      },       "id": 76,       "start": "2019-11-04T00:00:00.000Z",       "title": "Title 2",       "url": ""    }  ]}但是 FullCalendar 不顯示這兩個接收到的事件。我不知道我做錯了什么。問候。
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

發生這種情況是因為您的服務器必須返回一個僅包含事件的簡單數組,而沒有其他任何內容。您正在返回一個復雜的對象。FullCalendar 不知道如何解包您的對象并找到包含相關數據的“事件”屬性。


您需要簡單地返回:


[

 {

  "allDay": 1, 

  "color": "blue", 

  "end": "2019-10-24T00:00:00.000Z", 

  "extendedProps": {

    "company": "Company 1", 

    "state": "Active", 

    "type": "task"

  }, 

  "groupId": "48", 

  "id": 27, 

  "start": "2019-10-23T00:00:00.000Z", 

  "title": "Title 1", 

  "url": ""

 }, 

 {

  "allDay": 1, 

  "color": "blue", 

  "end": "2019-11-07T00:00:00.000Z", 

  "endpoints": 0, 

  "extendedProps": {

    "company": "All", 

    "description": "Description", 

    "creationDate": "2019-11-04", 

    "state": "Active", 

    "tecnology": "test", 

    "element": "test 1", 

    "type": "type 2", 

    "user": "user 1", 

    "version": "1.2"

  }, 

  "id": 76, 

  "start": "2019-11-04T00:00:00.000Z", 

  "title": "Title 2", 

  "url": ""

 }

]

從您的服務器,沒有它的其余部分。


我必須說 fullCalendar 文檔并沒有特別清楚地說明這一事實。


注意,我認為“錯誤”屬性無論如何都是多余的,在任何 JSON 響應中。如果出現錯誤,您應該返回一個指示錯誤性質的 HTTP 狀態代碼,以及一個完全不同的響應正文,指示您想告訴用戶有關錯誤的任何內容。這將在您的 JS 中觸發“失敗”回調,并允許瀏覽器代碼做出適當的響應。


查看完整回答
反對 回復 2021-12-02
  • 1 回答
  • 0 關注
  • 288 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號