为了账号安全,请及时绑定邮箱和手机立即绑定

如何获得 fullcalendar v.4.2.0 实例?

如何获得 fullcalendar v.4.2.0 实例?

牛魔王的故事 2021-08-20 14:34:23
所以我的页面中有一个 fullCalendar (v.4.2.0) 实例(在 document.ready 上加载/构建),我想在其他函数中访问该 fullCalendar 实例以动态添加事件。使用$('#calendar').fullCalendar('getView')它会显示 fullCalendar() 方法不存在的错误:$(...).fullCalendar 不是函数如何访问该实例?我用来生成日历的代码如下:var calendarEl = document.getElementById('calendar');var calendar = new FullCalendar.Calendar(calendarEl, {    plugins: [ 'timeGrid', 'dayGrid' ],        defaultView: 'timeGridWeek',         height: 700,        locale: 'pt',        allDaySlot: false,        handleWindowResize: true,        events: [            {                title: 'Teste1', // a property!                start: '2019-07-23 16:00',                 end: '2019-07-23 17:00',                 backgroundColor: '#fcba03',                borderColor: '#fcba03',            }        ]    });calendar.render();
查看完整描述

2 回答

?
智慧大石

TA贡献1946条经验 获得超3个赞

由于您使用的是 fullCalendar 版本 4,它不再被编写为 jQuery 插件,因此无法使用 jQuery 语法来访问这些方法。相反,只需引用您的calendar变量(它可能需要在您的应用程序中具有广泛的范围 - 全局或易于通过其他方式访问)。您会注意到现有代码在调用calendar.render();.


此外,在“getView”方法的特定情况下,这已被简单地替换view为引用当前视图的属性。


例如(见最后一行):


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

var calendar = new FullCalendar.Calendar(calendarEl, {

    plugins: [ 'timeGrid', 'dayGrid' ],

        defaultView: 'timeGridWeek', 

        height: 700,

        locale: 'pt',

        allDaySlot: false,

        handleWindowResize: true,

        events: [

            {

                title: 'Teste1', // a property!

                start: '2019-07-23 16:00', 

                end: '2019-07-23 17:00', 

                backgroundColor: '#fcba03',

                borderColor: '#fcba03',

            }

        ]

    });


calendar.render();


var vw = calendar.view; //get the current view


查看完整回答
反对 回复 2021-08-20
?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

**Create a config variable like below in js**


uiConfig = {

        calendar: {

          height: 450,

          editable: true,

          eventClick: alertEventOnClick,

          eventDrop: alertOnDrop,

          eventResize: alertOnResize,

          eventRender: eventRender

        }

      };


**defines the above methods in js file**


alertEventOnClick = function (date, jsEvent, view) {}

alertOnDrop = function (date, jsEvent, view) {}

alertOnResize = function (date, jsEvent, view) {}

eventRender = function (date, jsEvent, view) {}


**and in html add below lines of code**


<div ui-calendar="uiConfig.calendar" id="myCalendar" calendar-watch-event="extraEventSignature(event)"

    calendar="myCalendar" data-ng-model="eventSources">

  </div>


**The Following code is another way of accessing calendar**


$('#myCalendar').fullCalendar({

  eventClick: function(event, element) {


    event.title = "CLICKED!";


    $('#calendar').fullCalendar('updateEvent', event);


  }

});


**where Mycalender should be added in HTML like below**


<div ui-calendar="uiConfig.calendar" id="myCalendar"

    calendar="myCalendar" data-ng-model="eventSources">

  </div>


查看完整回答
反对 回复 2021-08-20
  • 2 回答
  • 0 关注
  • 198 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信