0

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
asked Dec 15, 2014 at 20:58
2
  • 1
    You simply define it before you call the .fullCalendar function and then use it's variable name in the function. Commented Dec 15, 2014 at 21:00
  • Where are you getting the data from? How is the data created? Commented Dec 15, 2014 at 21:01

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.