2016-02-23 27 views
1

我與fullcalander工作事件的數量。我想將每天創建的事件數量限制在4周內。 我看到這個鏈接,但它是有很大幫助,不僅 stackoverflow question eventLimit選項限制顯示的事件,但我想停下來,一旦6個事件每天在本週視圖中創建創建事件。 任何幫助將不勝感激,請耐心等待,因爲我是這個領域的新手。限制在fullcalander每天創建

+0

你嘗試過什麼 – madalinivascu

+0

現在我試圖計算與我的計算器 eventAfterAllRender發現代碼中的事件:功能(視圖){ VAR allevents = $(「#日曆」)fullCalendar(「clientEvents」 ); var countevents = 0; 如果(allevents.length){ countevents = countevents + allevents.length; } 如果(!countevents){// 警報( '事件計數爲' + countevents); console.log('event count is',countevents); } }; –

+0

你在哪裏編寫代碼來創建事件?請提供您嘗試過的更多內容。 –

回答

0

深挖洞,並更多地瞭解fullcalender後好了,這是我做到了。我必須說,這很容易。 `

var event_count=0;// to count the number of events starting from zero 
 
\t $(document).ready(function() { 
 
\t 
 
\t \t $('#calendar').fullCalendar({ 
 
\t \t \t header: { 
 
\t \t \t \t left: 'prev,next today', 
 
\t \t \t \t center: 'title', 
 
\t \t \t \t right: 'month,agendaWeek,agendaDay' 
 
\t \t \t }, 
 
\t \t \t defaultDate: '2016-01-12', 
 
\t \t \t editable: true, 
 
\t \t \t selectable: true, 
 
\t \t \t minTime: '09:00:00', 
 
\t \t \t maxTime: '18:00:00', 
 
\t \t \t columnFormat: 'dddd', 
 
\t \t \t eventLimit: true, 
 
\t \t \t select: function(start, end) { 
 
\t \t \t \t \t var eventData = { 
 
\t \t \t \t \t \t start: start, 
 
\t \t \t \t \t \t end: end 
 
\t \t \t \t \t }; 
 
\t \t \t \t event_count+=1;//if the control is inside this function increment eventcount 
 
\t \t \t \t if(event_count<4){ 
 
        //if the counter is less than four then do this 
 
\t \t \t \t \t $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true 
 
\t \t \t \t \t $('#calendar').fullCalendar('unselect'); 
 
\t \t \t \t \t } 
 
\t \t \t }, 
 
\t \t \t eventClick: function(event){ 
 
\t \t \t \t 
 
\t \t \t $('#calendar').fullCalendar('removeEvents',event._id); 
 
\t \t \t event_count-=event_count;//decrement event_count when event is removed 
 
\t \t \t }, 
 
\t \t \t loading: function(bool) { 
 
\t \t \t \t $('#loading').toggle(bool); 
 
\t \t \t } 
 
\t \t \t 
 
\t \t }); 
 
\t \t 
 
\t \t $('#view_calendar').on('shown.bs.modal', function() { 
 
    \t \t $("#calendar").fullCalendar('render'); 
 
\t \t 
 
}); 
 
\t \t 
 
\t })

`

1

試試這個。

select: function(start, end, jsEvent, view) { 
    var eventCounter = 0; 
    $('#calendar').fullCalendar('clientEvents', function(event) { 
     if (start.format('YYYY-MM-DD') == event.start.format('YYYY-MM-DD')) { 
      eventCounter++; 
     } 
    }); 
    if (eventCounter < 6) { 
     // Code to create event 
    } 
} 

這適用於我當地。