FullCalendar v4将onclick eventListener添加到eventLimitClick popover上显示的事件

时间:2019-11-27 08:48:43

标签: javascript fullcalendar popover fullcalendar-4

我使用FullCalendar v4 js进行了自定义开发,但是遇到eventLimitClick方法的问题。

当我单击它时,我希望在弹出框内显示的所有事件都有一个自定义onclick eventListener,让我在另一个自定义弹出窗口中显示此当前事件的附加信息。

到目前为止,这是我的方法:

eventLimitClick : function(info){
    info.segs.forEach(function(seg){
        seg.el.querySelector('div.fc-content').addEventListener('click', function(event){
            console.log('event definition', event);
        });
    });
    return "popover";
}

但这会将侦听器添加到我在日历中已经看到的元素。我也尝试过使用hiddenSegs而不是段,但是它不起作用。

那么有什么方法可以实现而不必创建带有所有事件的自定义弹出窗口?

**编辑** [包含的代码]

日历对象

     {
        locale : 'en',
        plugins : ['dayGrid','timeGrid','list','interaction'],
        header : {
            left : 'prev,next today',
            center : 'title',
            right : 'dayGridWeek, dayGridMonth, dayGridDay'
        },
        allDaySlot : false,
        aspectRatio : 1.8,
        displayEventTime : false,
        editable : false,
        navLinks : true,
        eventLimit : true,
        views : {
            dayGridMonth : {
                eventLimit : 2
            }
        },
        events : this.eventLIST,
        datesRender : this.calendarviewRender,
        eventClick : this.calendareventClick,
        eventRender : this.calendareventRender
     }

datesRendereventClickeventRender函数:

calendarviewRender = (info) => {
    //set current and end dates
    this.endDate = info.view.activeEnd;
    this.currentDate = info.view.activeStart;
    //retrieve fresh event/task info
    this.refreshCalendar();
}
calendareventClick = (info) => {
    this.info = {id : info.event.id,
                 tipo : info.event.extendedProps.tipo,
                 tipoObj : info.event.extendedProps.tipoObj,
                 isClosed : info.event.extendedProps.isClosed && info.event.extendedProps.isClosed !== null ? (info.event.extendedProps.isClosed === 'false' ? false : true) : false,
                 campos : info.event.extendedProps.lCamposInfo};
    //allow second button
    this.info.displaysecondbutton = !this.info.isClosed && this.info.tipoObj === 'Task';
    //allow popup display
    this.allowpopup = true;
    info.jsEvent.preventDefault();
}
calendareventRender = (info) => {       
    let html = "<i class='fa fa-" + info.event.extendedProps.icon + " fa-lg'></i>";
    info.el.querySelector('div.fc-content').style.cssText = 'height: 100%;';
    //if month view apply padding
    if(info.view.type.includes('dayGrid')) info.el.querySelector('div.fc-content').classList.add('slds-p-around_x-small');
    //center elements
    info.el.querySelector('div.fc-content').classList.add('slds-align_absolute-center');
    //append icon
    info.el.querySelector('div.fc-content').innerHTML = html;
}

我还删除了eventLimitClick

1 个答案:

答案 0 :(得分:2)

根据您的评论,我看到您正在使用lightning-web-components。

在LWC上与Salesforce合作时,我遇到了与您相同的问题。

我可以通过在daygrid包中编辑main.js来解决此问题,并在Popover隐藏时增加延迟。

这是代码段

function Popover(options) {
        var _this = this;
        this.isHidden = true;
        this.margin = 10; // the space required between the popover and the edges of the scroll container
        // Triggered when the user clicks *anywhere* in the document, for the autoHide feature
        this.documentMousedown = function (ev) {
            if (_this.el && !_this.el.contains(ev.target)) {
                setTimeout(function () {
                    _this.hide();
                }, 1000);
            }
        };
        this.options = options;
    }

功能从main.js的第100行开始。 我正在使用Fullcalendar v4

相关问题