I have a question regarding the next code, how can I fill the 'events' array dynamically, with a for / while ? ( I can't fill it manually due to the fact that there are a lot of datas ) Thank you
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek'
},
defaultDate: '2014-12-15',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'Test',
start: '2014-12-17'
}
]
});
});
</script>
suslov.nikita
44.7k11 gold badges92 silver badges113 bronze badges
2 Answers 2
You can use IIFE (immediately-invoked function expression)
events: (function () {
var events = [];
for (var i = 0; i < 10; i +=1) {
// You can do here anything.
events.push({
title: 'Test' + i,
start: '2014-12-17'
});
}
return events;
})()
Dave
11k3 gold badges45 silver badges54 bronze badges
answered Dec 15, 2014 at 21:03
Seva Arkhangelskiy
6853 silver badges12 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can create an array variable and then use it when you initialize the calendar like so:
var events = [];
for(var i = 0; i < 10; i++) {
events.push({title: 'Test' + i, start: '2014-12-17'});
}
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek'
},
defaultDate: '2014-12-15',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: events
});
answered Dec 15, 2014 at 21:03
Dave
11k3 gold badges45 silver badges54 bronze badges
Comments
lang-js
.fullCalendarfunction and then use it's variable name in the function.