2014-09-22 93 views
0

使用jQuery-UI的可放置小部件時,放置函數返回一個「ui」對象,您可以在其中訪問作爲拖動對象的DOM元素的「可拖動」對象。但是使用fullCalendar的drop函數,我得到了沒有「可拖動」的「ui」對象。這裏有一個在的jsfiddle你可以檢驗一下我說的是:http://jsfiddle.net/vfaethbd/在放置UI對象時獲取可拖動對象

$('#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。

感謝

回答

0

實現什麼樣的外部拖着例如在下降回調:

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
  • startEditable

如果沒有它可能看起來像失去了你的活動拖動選項

+0

拖放功能是好的,我沒有問題,它是與ui argum ent,它不像jQuery UI那樣返回可拖動的對象,我需要從我的可拖動對象中提取屬性信息 – ToniZ 2014-09-23 06:53:53