Kris
Kris

Reputation: 97

fullcalendar javascript array

I'm having troubles with a multidimensional array in javascript =>

I tried it with declaring several wayS. if i use this [[]] then only the [0]["title"] and [0]["start] are showed. I'm searching for hours without luck.

I want to put the result of this array in the fullcalendar script. I'm stuck.

function onLoadItemsSuccess(sender, args) {
    var listInfo = '';
    var listItemEnumerator = listItems.getEnumerator();
    var item;
    var listItemInfo = '';
    var index = -1;
    var datum = '';
    var i2 = 0;
    var verlofdagenarray = new Array();
    //var verlofdagenarray = [[]];

    while (listItemEnumerator.moveNext()) {
        item = listItemEnumerator.get_current();
        //alert("Item geeft nu het volgende weer" + item.toString());
        //alert(listEnumerator.get_current().get_item("Title"));
        var naam = item.get_item("Naam");
        var telefoonnummer = item.get_item("Telefoonnr");
        var mobiel = item.get_item("Mobielnr");
        var voornaam = item.get_item("Voornaam");
        var telefoonintern = item.get_item("TelefoonIntern");
        var adres = item.get_item("Adres");
        var postcode = item.get_item("Postcode");
        var gemeente = item.get_item("Gemeente");
        var land = item.get_item("Land");
        var departement = item.get_item("Departement");
        var functie = item.get_item("Functie");
        var verlofdatum = item.get_item("Verlofdatum");
        var emailadres = item.get_item("Emailadres");

        var d = new Date(verlofdatum);
        var curr_day = d.getDate();
        var curr_month = ('0' + (d.getMonth() + 1)).slice(-2)
        var curr_year = d.getFullYear();
        var verlofdatum2 = curr_year + "-" + curr_month + "-" + curr_day;

        verlofdagenarray = new Array(2);

        verlofdagenarray[i2]["title"] = voornaam + "" + naam;
        verlofdagenarray[i2]["start"] = verlofdatum2;
        i2++;

    }

    document.write(verlofdagenarray[0]["title"]);
    document.write(verlofdagenarray[0]["start"]);

    $('#calendar').fullCalendar({
        //eventSources: verlofdagenarray

        // put your options and callbacks here
    })
}

Upvotes: 0

Views: 170

Answers (2)

Kris
Kris

Reputation: 97

Thanks alot this is working.

Just a little question when i'm adding my own options to the fullcalendar the events aren't working anymore. See below

var options = {
    theme: true,
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    timeFormat: {
        agenda: 'h(:mm)t{ - h(:mm)t}',
        '': 'h(:mm)t{-h(:mm)t }'
    },
    monthNames: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
    monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
    dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
    dayNamesShort: ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
    buttonText: {
        today: 'vandaag',
        month: 'maand',
        week: 'week',
        day: 'dag'
    }
};


$('#calendar').fullCalendar(options,{

    theme: true,
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,


    events: verlofdagenarray


    // put your options and callbacks here
})

Upvotes: 1

bto.rdz
bto.rdz

Reputation: 6720

check this example:

How can I create a two dimensional array in JavaScript?

to create a bidimensional array in js you create an array of rows (that's how I see it).

in your case you have to do something like:

var row = { title: voornaam + "" + naam, start: verlofdatum2 }
verlofdagenarray.push(row);

push just adds that new element to your array, so after your look you will get something like:

verlofdagenarray = [ {title:1,start:1},{title:2,start:2},{title:3,start:3} ]

hope it helps!

Upvotes: 1

Related Questions