检测后台事件 [英] Detect background events

查看:106
本文介绍了检测后台事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用FullCalendar。我使用了后台事件, rendering =background。我如何检测用户是否点击了背景事件?

  dayClick:function(start,end,allDay,jsEvent,颜色,calEvent){
if(calevent.rendering ===background){
alert('Click Background Event Area');
}
else {
$('#modal1')。modal('show'); $(b)

$ b if(start.isBefore(moment())){
$('#calendar')。fullCalendar('unselect');
返回false;
}
},


解决方案

由于fullCalendar不会在后台事件中显示单击类型事件,因此我认为这样做的唯一方式实质上是一种DIY方法。基本思路:
$ b


  • 处理select事件

  • 获取当前所有在fullCalenar中的事件内存,使用clientEvents方法。
  • 循环遍历所有时间段并检查其中是否有背景事件,如果是,它们是否与选定时间段重叠。如果他们这样做,那么这就是点击的事件。



我没有测试过这个,但它是基于一些旧代码我发现,所以希望你有这个想法:

  select:function(start,end,jsEvent,view){
var cal = $(#calendar); //将日历元素的ID放在这里
var evts = cal.fullCalendar('clientEvents'); //获取所有内存事件
var selectedEvent = null;

for(i in evts){
if(evts [i] .rendering ==background&& start.isBefore(evts [i] .end)&& amp ; end.isAfter(evts [i] .start)){
selectedEvent = evts [i];
}
}
}

select允许选择一个时间段,而不仅仅是一次单击,所以它可能是选择与后台事件重叠,而不是完全包含在内。如果不适合你,你也许可以稍微调整逻辑 - 例如要求开始和结束都在事件的边界内。


I am using FullCalendar in my project. I used background events, rendering="background". How can I detect if user click on the background events? I try this but it doesnot work since all dates cannot be clicked.

dayClick: function (start, end, allDay, jsEvent, view,color,calEvent) {
            if (calevent.rendering==="background") {
                alert('Click Background Event Area');
            }
            else{
            $('#modal1').modal('show');
           }

            if (start.isBefore(moment())) {
                $('#calendar').fullCalendar('unselect');
                return false;
            }
        },

解决方案

Since fullCalendar doesn't expose an "click" type event on background events, the only way I can think of to do this is essentially a DIY approach. The basic idea:

  • Handle the "select" event
  • Fetch all the events currently in fullCalenar's memory, using the "clientEvents" method.
  • Loop through them all and check whether any of them are background events, and if so, whether they overlap with the selected time period. If they do, then that's the event that was clicked on.

I haven't tested this, but it's based on some old code I found, so hopefully you get the idea:

select: function(start, end, jsEvent, view) {
    var cal = $("#calendar"); //put the ID of your calendar element here
    var evts = cal.fullCalendar('clientEvents'); //get all in-memory events
    var selectedEvent = null;

    for (i in evts) {
        if (evts[i].rendering == "background" && start.isBefore(evts[i].end) && end.isAfter(evts[i].start)) {
            selectedEvent = evts[i];
        }
    }
}

The only flaw in this is that "select" allows selection of a time period, not just a single click, so it could be that the selection is overlapping the background event, and not wholly contained within it. You might be able to adjust the logic a little bit if that doesn't suit you - e.g. to require that both start and end are within the event's boundaries.

这篇关于检测后台事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆