2

外部イベントをカレンダーにドラッグアンドドロップする機能があります。開始時刻のデフォルトの動作は、イベントがドロップされた場所です。デフォルトの動作を設定して、イベントの終了時刻も開始時刻の1時間後に設定したいと思います。これは些細なことのようですが、私はそれを機能させることができないようです。以下は私のドロップ機能です(基本的にドロップ可能なアイテムのデモに1行を加えたものです)。

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.start = date;
    copiedEventObject.end = date.setHours(date.getHours()+1); // <- should be working
    copiedEventObject.allDay = allDay;

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

何か案は?

ありがとう、ジョー・チン

4

4 に答える 4

5

あなたがやろうとしていることのその例の問題は、それallDayがtrueに設定されているため、開始日に指定された時間を無視することです。午前 0 時がデフォルトの午前 1 時であることに満足している場合は、次のようにします。

var tempDate = new Date(date);  //clone date
copiedEventObject.start = date;
copiedEventObject.end = new Date(tempDate.setHours(tempDate.getHours()+1)); // <-- make sure we assigned a date object
copiedEventObject.allDay = false;  //< -- only change
....

編集:OK、私は実際にこのバージョンを試しました。 うまくいくようです。

于 2010-11-12T22:29:25.167 に答える
1

カレンダー プロパティ

http://arshaw.com/fullcalendar/docs/agenda/defaultEventMinutes/ 開始からのデフォルトの終了時間を設定します

于 2013-07-26T13:15:29.060 に答える
0

Ryley が投稿したソリューションを正しく機能させることができませんでした。外部イベントがカレンダーのヘッダーに配置され、週を表示すると、イベントが細い線 (折りたたまれているように見える) になるか、まったく表示されません。これは、fullCalendar のバージョンの違いかもしれません (fullCalendar の v2 を使用しています)。fullCalendar の v2 では、どのカレンダー ビュー内のイベントでも問題なく動作させることができました。

drop: function (date, jsEvent, ui) { // this function is called when an external element 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);

    var sdate = $.fullCalendar.moment(date.format());  // Create a clone of the dropped date.
    sdate.stripTime();        // The time should already be stripped but lets do a sanity check.
    sdate.time('08:00:00');   // Set a default start time.
    copiedEventObject.start = sdate;

    var edate = $.fullCalendar.moment(date.format());  // Create a clone.
    edate.stripTime();        // Sanity check.
    edate.time('12:00:00');   // Set a default end time.
    copiedEventObject.end = edate;

    // 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);

},
于 2014-08-22T15:24:13.863 に答える