Fullcalendar:同一天的多个事件集中在一个事件中

发布于 2025-01-01 14:01:49 字数 3513 浏览 1 评论 0原文

我有一个带有周视图的全日历。

我已修改 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', CopyEventObject, true);

萤火虫 说: 没有方法“替换”

未捕获的类型错误:对象 2在此函数中

 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)

I have a Fullcalendar with the week view.

I have modified fullcalendar to show a number with the event:

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;
}

in the drop function:

        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();
            }

        },

but when I drop the second event in the same day and hour, all events disapear.

sorry for my english.

I think the blame line is:
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

firebug says:
Uncaught TypeError: Object 2 has no method 'replace'

in this function

 function htmlEscape(s) {
      return s.replace(/&/g, '&')
      .replace(/</g, '<')
    .replace(/>/g, '>')
    .replace(/'/g, ''')
    .replace(/"/g, '"')
    .replace(/\n/g, '<br />');
 }

(fullcalendar.js)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

优雅的叶子 2025-01-08 14:01:49

使用全日历的Eventlimit,
假设您想对单日的所有事件进行分组,那么只需将事件限制设置为 1,如下所示:

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

Use Eventlimit of Full Calendar ,
Suppose You want to Group all Events of Single day then Just set limit of event to 1 as follows:

$('#divCalendar').fullCalendar({                    
                        theme: true,
                        eventLimit: true, // for all non-agenda views
                        eventLimit: 1,
......
further code
我们只是彼此的过ke 2025-01-08 14:01:49

我用这一行解决了问题:

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

因为 function "function htmlEscape(s) {" "s" 必须是字符串

谢谢!

I solved the problem with this line:

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

because function "function htmlEscape(s) {" "s" must be an string

Thank you!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文