第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

fullcalendar.io 5:addEventSource 無(wú)法通過外部函數(shù)工作

fullcalendar.io 5:addEventSource 無(wú)法通過外部函數(shù)工作

富國(guó)滬深 2023-09-28 15:31:13
對(duì)于一個(gè)小項(xiàng)目,我想在運(yùn)行時(shí)添加事件。實(shí)際的日歷是使用數(shù)據(jù)庫(kù)中的數(shù)據(jù)創(chuàng)建的。單獨(dú)的腳本創(chuàng)建其他事件,這些事件是在日歷運(yùn)行時(shí)動(dòng)態(tài)創(chuàng)建的。這些事件隨后應(yīng)添加到現(xiàn)有日歷中。為了進(jìn)行測(cè)試,我有一個(gè)日歷和一個(gè)外部按鈕。如果單擊該按鈕,則會(huì)將事件添加到日歷中。創(chuàng)建日歷并識(shí)別單擊。但沒有添加任何事件。思想錯(cuò)誤在哪里?超文本標(biāo)記語(yǔ)言<button class="holiday">Add Feiertage</button> <div id='calendar'></div>代碼:document.addEventListener('DOMContentLoaded', function() {  var calendarEl = document.getElementById('calendar');  var calendar = new FullCalendar.Calendar(calendarEl, {    headerToolbar: {      left: 'prev,next today',      center: 'title',      right: 'dayGridMonth,timeGridWeek'    },    initialDate: '2020-11-12',    businessHours: true, // display business hours    editable: true,    events: [      {        title: 'Business Lunch',        start: '2020-11-03T13:00:00',        constraint: 'businessHours'      },      {        title: 'Meeting',        start: '2020-11-13T11:00:00',        constraint: 'availableForMeeting', // defined below        color: '#257e4a'      },      {        title: 'Conference',        start: '2020-11-18',        end: '2020-11-20'      },      {        title: 'Party',        start: '2020-11-29T20:00:00'      },      // areas where "Meeting" must be dropped      {        groupId: 'availableForMeeting',        start: '2020-11-11T10:00:00',        end: '2020-11-11T16:00:00',        display: 'background'      },      {        groupId: 'availableForMeeting',        start: '2020-11-13T10:00:00',        end: '2020-11-13T16:00:00',        display: 'background'      },      // red areas where no events can be dropped      {        start: '2020-11-18',        title: 'Test-Holiday',        overlap: false,        display: 'background',        color: '#ff9f89'      }    ]  });  calendar.render();});這是我的測(cè)試: https: //jsfiddle.net/LukasHH/tu14xfwr/
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

calendar您使用的變量引用的是calendar.addEventSource與頁(yè)面上顯示的不同的 FullCalendar 實(shí)例。您創(chuàng)建了一個(gè)全新的日歷 - 但隨后沒有將其呈現(xiàn)到頁(yè)面上。這就是為什么你不會(huì)收到錯(cuò)誤,但也沒有發(fā)生任何有用的事情。


原始?jí)Kcalendar已在您的塊內(nèi)定義并填充document.addEventListener('DOMContentLoaded', function() {,但您嘗試在塊內(nèi)創(chuàng)建一個(gè)新塊jQuery(document).ready(function($) {。您需要使用現(xiàn)有的引用calendar- 但當(dāng)然,當(dāng)您需要它時(shí)它超出了范圍,因?yàn)槟挥诓煌拇a塊中。


現(xiàn)在,document.addEventListener('DOMContentLoaded', function() {和jQuery(document).ready(function($) {本質(zhì)上是等價(jià)的,只是一個(gè)是用原生JS編寫的,一個(gè)是jQuery語(yǔ)法。它們基本上執(zhí)行相同的任務(wù) - 即延遲代碼的執(zhí)行,直到 DOM 完全加載。因此,將它們同時(shí)放在頁(yè)面中沒有多大意義或增加任何價(jià)值。只需使用一個(gè)塊來(lái)包含所有代碼,然后您就不會(huì)遇到任何范圍問題。


除此之外,出于類似的原因,document.addEventListener('DOMContentLoaded', function() { 在jQuery“就緒”塊中再有另一個(gè)也是沒有意義的!你根本不需要它。我只能假設(shè)您不理解該代碼的作用并認(rèn)為它是 fullCalendar 的一部分 - 事實(shí)并非如此。



var i = calendar.initialEvents();

console.log(i);    

沒有意義。fullCalendar 中沒有名為initialEvents 的方法,并且您似乎并沒有嘗試使用i任何方法,因此您可以刪除這些行。


例如


jQuery(document).ready(function($) {

  var calendarEl = document.getElementById('calendar');

  var calendar = new FullCalendar.Calendar(calendarEl, {

    //...etc

  });

  calendar.render();


  $('.holiday').on('click', function() {

    calendar.addEventSource({

      events: [ // put the array in the `events` property

      {

        title: 'Test-Event',

        start: '2020-11-11',

        overlap: false,

        display: 'background',

        color: '#ff9f89'

      }

    ]

  });

});

演示: https: //jsfiddle.net/32w4kLvg/


查看完整回答
反對(duì) 回復(fù) 2023-09-28
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)