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

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

Comments

Your Answer

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.