Fullcalendar:在同一天的单个活动中分组活动

时间:2012-02-02 15:28:59

标签: events numbers fullcalendar show

我有一个带有周视图的Fullcalendar。

我修改了fullcalendar以显示事件编号:

function slotSegHtml(event, seg) {

[...]

    html +=
        " class='" + classes.join(' ') + "'" +
        " style='position:absolute;z-index:8;top:" + seg.top + "px;left:" + seg.left + "px;" + skinCss + "'" +
        ">" +

                    "<span class='fc-event-inner fc-event-qty'>"+htmlEscape(event.qty)+"</span>"+                              

[...]
    return html;
}
drop函数中的

        drop: function(date, allDay) { // this function is called when something is dropped

            // retrieve the dropped element's stored Event Object
            var originalEventObject = $(this).data('eventObject');

            // we need to copy it, so that multiple events don't have a reference to the same object
            var copiedEventObject = $.extend({}, originalEventObject);

            // assign it the date that was reported
                            copiedEventObject.id = idevento++;
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;

                            copiedEventObject.className = 'newEvent';
                            copiedEventObject.qty = '1';



                            //buscar eventos
                            var listevents = $('#calendar').fullCalendar('clientEvents',function(event) {
                                if(date.getFullYear()!=event.start.getFullYear())return false;

                                if(date.getMonth()!=event.start.getMonth())return false;

                                if(date.getDay()!=event.start.getDay())return false;

                                if(date.getHours()!=event.start.getHours())return false;     


                                //aparte tienen que ser del mismo tipo
                                if(event.title!=copiedEventObject.title)return false;

                                return true;
                            });


                            if(typeof listevents === 'object'){

                                //augmentar la cantidad
                                eventoantiguo = listevents[0];

                                copiedEventObject.qty = parseInt(eventoantiguo.qty)+1;

                                //borrar el objeto antiguo
                                $("#calendar").fullCalendar('removeEvents', eventoantiguo.id);

                            }

            // render the event on the calendar
            // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)


                            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);


            // is the "remove after drop" checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
            }

        },

但是当我在同一天和小时内放弃第二个事件时,所有事件都会消失。

抱歉我的英语。

我认为责任是: $('#calendar')。fullCalendar('renderEvent',copiedEventObject,true);

萤火虫说: 未捕获的TypeError:对象2没有方法'replace'

在这个函数中

 function htmlEscape(s) {
      return s.replace(/&/g, '&amp;')
      .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/'/g, '&#039;')
    .replace(/"/g, '&quot;')
    .replace(/\n/g, '<br />');
 }

(fullcalendar.js)

2 个答案:

答案 0 :(得分:2)

使用完整日历的Eventlimit, 假设您要对单日的所有事件进行分组,然后将事件限制设置为1,如下所示:

$('#divCalendar').fullCalendar({                    
                        theme: true,
                        eventLimit: true, // for all non-agenda views
                        eventLimit: 1,
......
further code

答案 1 :(得分:1)

我用这一行解决了这个问题:

 copiedEventObject.qty = (parseInt(eventoantiguo.qty)+1)+'';//se tiene que convertir a string!

因为函数&#34;函数htmlEscape(s){&#34; &#34; S&#34;必须是一个字符串

谢谢!