REACT(cra):当试图在fullcalendar的“eventRender”中使用jQuery时,我得到错误:$ el.popover不是函数

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

我正在尝试使用fullcalendar docs的建议实现在日历事件中实现popover选项,但是当我编写使用popover方法和jQuery的回调函数时,我得到错误:

TypeError:$ el.popover不是函数

这是我的代码的一小部分。

class CalendarComponent extends React.Component {

    componentDidMount = () => {
        this.init();
    }  

  init = () => {
    [...]

        $('#calendar').data("activityAssignedEvents", activityAssignedEvents);
        $('#calendar').fullCalendar({
            header: false,
            defaultView: "timelineDay",
            height: "auto",
            slotLabelFormat: "HH",

            // businessHours: businessHours,
            themeSystem: "bootstrap4",
            slotLabelInterval: "02:00:00",
            slotDuration: "01:00:00",
            nowIndicator: true,
            now: moment.utc(),
            timezone: "local",
            locale: "pt-br",
            events: activityAssignedEvents,
            eventRender: function (eventObj, $el) {
                $el.popover({
                    title: eventObj.title,
                    content: eventObj.description,
                    trigger: 'hover',
                    placement: 'top',
                    container: 'body'
                });
            },

        });
  }
}

我的进口:

import $ from 'jquery';
import 'fullcalendar';

我不知道如何解决这个问题。

我已经尝试使用npm更新jQuery和Bootstrap版本,但没有任何改变。

jquery reactjs fullcalendar tooltip popover
1个回答
0
投票

一些想法..尝试:

  1. 在使用$el = $($el);之前,在eventRender函数中使用$el.popover(...(它可能不是jQuery对象)
  2. 将日历库js文件和jquery添加到index.html内的标头中
  3. 确保在加载库后执行脚本
© www.soinside.com 2019 - 2024. All rights reserved.