2014-01-18 21 views
1

在fullCalendar的dayClick FullCalendar顯示事件被定義。上dayClick

我想在用戶點擊某一天時訪問事件的數據。在dayClick中合併eventClick函數以便當我點擊特定日期時,我可以獲得特定日期發生的所有事件的事件標題,開始時間和結束時間。

+0

如果一天不包含任何事件會怎麼樣? –

+0

@RahilWazir:在這種情況下,我想它會給一個'null'。我的意思是,假設我們將事件存儲在一個數組中,那麼該數組將爲null。 – xan

+0

那你爲什麼不使用[eventClick](http://arshaw.com/fullcalendar/docs/mouse/eventClick/) –

回答

1

我希望這可以幫助您

$('#calendar').fullCalendar({ 
     dayClick: function(date, allDay, jsEvent, view) { 
       var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 0, 0, 0).getTime(); 
       var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 23, 59, 59).getTime(); 
       var cache = new Date().getTime(); 
       $.getJSON("/json-events.php?start="+startDate+"&end="+endDate+"&_="+cache, 
        function(data) { 
         // do stuff with the JSOn data 
        } 
     } 
    }); 
+0

我不知道這將如何幫助。我已經有一些特定事件的日曆。當我點擊某一天(當天發生的所有事件的標題)時,我只想顯示事件的標題。此外,您的代碼不起作用。 – xan

+0

爲什麼不呢?我認爲是在這裏問同樣的問題:http://stackoverflow.com/questions/2516050/in-the-fullcalendar-dayclick-event-can-i-get-the-events-that-already-exist-in-c – user2183923

0

你可以試試這個:

eventClick: function(xEvent, jsEvent, view) { 
    alert("Title: " + xEvent.title    //Get the event title 
      + "\n StartTime: " + xEvent.start //Get the event start date 
      + "\n EndTime: " + xEvent.end  //Get the event end date 
    ); 

    console.log(xEvent); //See your console for all event properties/objects 
} 

xEvent性能/對象名單。

+0

當用戶點擊一個「事件」時觸發。當用戶點擊「日」時,我需要事件數據。 – xan

+0

@ con_28如果一天沒有事件發生,那當然沒有事件數據。只有在當天有事件登記的情況下才能獲取事件數據。 –

+0

就我而言,除了星期天以外,所有的日子都至少有一次。 – xan

0
dayClick: function(date, allDay, jsEvent, view) { 
    var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 0, 0, 0).getTime(); 
    var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDay(), 23, 59, 59).getTime(); 
    var cache = new Date().getTime(); 
    $.getJSON("/json-events.php?start="+startDate+"&end="+endDate+"&_="+cache, 
     function(data) { 
      // do stuff with the JSOn data 
    }); 
    alert('ENTROU!'); 
}, 

現在的作品

它會打開一個警告,你就必須把信息通緝。

0

我認爲這就是你要找的。

dayClick: function(date, allDay, jsEvent, view) { 
    var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate()+1); 
    //This gives the next day of the clicked day('date' contains the clicked day) 

    var todaysEvents = $('#calendar').fullCalendar('clientEvents', function(event) { 
    // Below statement returns the EVENT OBJECT of the clicked day after comparing the two dates 
    return event.start >= date && event.start < date2; 
    }); 
    // You can now access the returned object & extract what you want 
    // console.log(todaysEvents); --> returns the complete object 
    // console.log(todaysEvents[0].title); --> returns that day's event title 
}, 

我希望這有助於。

+0

您首先必須使用toDate函數將時間從js轉換爲javascript日期。所以jsDate = date.toDate(),並使用jsDate而不是日期 – danpop

+0

date.getDate()+ 1不會工作...這可能是32.無效的日期。 – rob345

相關問題