简体   繁体   English

单击custombutton时事件的完整日历执行顺序

[英]fullcalendar execution order of events when click custombutton

What I am trying to make is a filter button that when user click it, and type the resource name, then the events that only match with the resource name is seen. 我想要做的是一个过滤器按钮,当用户单击它时,键入资源名称,然后将看到仅与资源名称匹配的事件。 At first, all of the events are rendered. 首先,将渲染所有事件。 then, when user click the search button, then only the events that match with the resource that user typed is viewed. 然后,当用户单击搜索按钮时,仅查看与用户键入的资源匹配的事件。 I make this by using removeEvents, which remove all the events that didn't satisfy the condition. 我通过使用removeEvents来做到这一点,它会删除所有不满足条件的事件。 However, the problem is, after searching one time, if user typed another resource name, then no events are viewed, because the events that user searched is already removed. 但是,问题是,在搜索一次之后,如果用户键入了另一个资源名称,则不会查看任何事件,因为已经删除了用户搜索的事件。 Thus, I add refetchEvents before removeEvents. 因此,我在removeEvents之前添加refetchEvents。 However, this time, no events are removed, and all of the events are viewed because of refetchEvents, even if I typed it before the removeEvents. 但是,这一次,不会删除任何事件,并且由于refetchEvents会查看所有事件,即使我在removeEvents之前键入了它也是如此。 Here is the code 这是代码

myCustomButton1: {
              text: 'filter by resource',

              click: function() {

                $("#calendar").fullCalendar('refetchEvents');
                var teachername = prompt("type the name of teacher");
                var teacherlist = <?php echo $json_array8; ?>;
                var exist = false;
                if(prompt)
                {   


                    for(var i = 0; i < teacherlist.length ; i++)
                    {
                        if(teacherlist[i]["courseTeacher"] == teachername)
                        {
                            exist = true;
                        }

                    }
                }
                if(!exist)
                {
                    alert("check the resource name.");
                }
                else
                {

                    $('#calendar').fullCalendar('removeEvents', function (calEvent) {
                                if(calEvent.resourceId != teachername)
                                {
                                    return true;
                                }else
                                {
                                    return false;
                                }

                        });

                }
             }
            }

Do not use removeEvents. 不要使用removeEvents。 As per the documentation ( https://fullcalendar.io/docs/removeEvents ), removeEvents completely removes the events from the calendar object. 根据文档( https://fullcalendar.io/docs/removeEvents),removeEvents会从日历对象中完全删除事件。 Which is why you do not find the events when you type in a new search string. 这就是为什么当您输入新的搜索字符串时找不到事件的原因。

Instead what you could do is use element.hide() and element.show() in the eventRender callback. 相反,您可以做的是在eventRender回调中使用element.hide()和element.show()。

eventRender: function(event, element){
    var teacherlist = <?php echo $json_array8; ?>;
    if(prompt)
    {   


        for(var i = 0; i < teacherlist.length ; i++)
        {
            if(teacherlist[i]["courseTeacher"] == teachername)
            {
                exist = true;
            }

        }
    }

    if(exist)
    {
        element.hide();
    }
    else
    {
        element.show();
    }

}

Note: The downside to using show/hide is that in the month view, the way fullcalendar works is that it renders the events in a table structure. 注意:使用show / hide的缺点是在月视图中,fullcalendar的工作方式是将事件呈现在表结构中。 So if you hide an event the events do not 'flow up' and as such, you will have some empty gaps in between which may look like a rendering issue. 因此,如果隐藏事件,事件将不会“流动”,因此,它们之间将存在一些空白,这看起来像是渲染问题。 To get by this display you issue, you will have no choice but to re-render all the events using a new eventSource. 要获得显示效果,您将别无选择,只能使用新的eventSource重新渲染所有事件。 One easy method is to ensure that the eventSource you use makes an ajax call. 一种简单的方法是确保您使用的eventSource进行ajax调用。 You can ensure that in your ajaxCall you pass your search string and do the processing in your ajax file. 您可以确保在ajaxCall中传递搜索字符串并在ajax文件中进行处理。 The returned value will be the filtered events that you want to be rendered. 返回的值将是您要呈现的已过滤事件。 You wont get a display issue here as reRenderEvents is possibly called internally. 由于reRenderEvents可能在内部调用,因此您不会在这里看到显示问题。 Again, the downside to this particular method is that you would have to make ajax calls everytime you want to filter the calendar events. 同样,此特定方法的缺点是,每次要过滤日历事件时,都必须进行ajax调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM