【问题标题】:Get draggable object in the ui object on drop在放置时获取 ui 对象中的可拖动对象
【发布时间】:2014-09-22 15:35:09
【问题描述】:

当使用 jQuery-UI 的 droppable 小部件时,drop 函数返回一个“ui”对象,您可以在其中访问一个“draggable”对象,该对象是被拖动对象的 DOM 元素。但是使用 fullCalendar 的 drop 功能,我得到了没有“可拖动”对象的“ui”对象。这是一个 JSFiddle,您可以在其中测试我在说什么:http://jsfiddle.net/vfaethbd/

 $('#calendar').fullCalendar({
      header: {
        left: 'title',
        center: 'agendaDay,agendaWeek,month',
        right: 'today prev,next'
      },
      droppable: true,
      drop: function (date, jsEvent, ui) {
        alert(JSON.stringify(ui, null, 4));
      }
    });

    $("#droppable-area").droppable({
      drop: function (event, ui) {
        alert(JSON.stringify(ui, null, 4));
      }
    });
    /* returns  "draggable": {
            "0": {
                "jQuery111104109880250544967": 6
            },
            "context": {
                "jQuery111104109880250544967": 6
            },
            "length": 1
        }
    */

如果你在日历中放置一个事件,你不会有可拖动的对象,但是如果你把它放在另一个可放置的区域你会得到它,因为这个使用 jQuery-UI。

谢谢

【问题讨论】:

    标签: jquery-ui fullcalendar


    【解决方案1】:

    在 drop 回调中实现外部拖动示例的功能:

    drop: function(date) { // 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.start = date;
    
                // 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();
                }
    
            }
    

    完整的代码示例here 和有关外部事件的文档here

    另外,请确保您的活动和日历是可编辑的,这包括:

    • 全天
    • durationEditable
    • 开始编辑

    如果不是,您的活动似乎失去了拖动选项

    【讨论】:

    • drop 功能很好,我没有问题,问题在于 ui 参数,它不会像 jQuery UI 那样返回可拖动对象,我需要从中提取属性等信息我的可拖动对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    相关资源
    最近更新 更多