handling a full calendar event object

Wanted to know how I create an object and fill him with info so I can add him to the full calendar jquery plugin. So far I did something like :

            var eventsArray = [];
            var newEvent = new Object();

            newEvent[title] = "some text";
            newEvent[start] = d1;        //got date string here exactly similar to the calendar's
            eventsArray.push(newEvent);

             var formattedEventData = [] ;
            for (var k = 0; k < eventsArray.length; k ++) {
                formattedEventData.push({

                    title: eventsArray[k][0],
                    start: eventsArray[k][1]
                });
            }

             $('#calendar').fullCalendar({
                  eventsource: formattedEventData,
                  events: formattedEventData,
                    color: 'yellow',
                    textColor: 'black'
            });
              $('#calendar').fullCalendar('addEventSource',formattedEventData);
              $('#calendar').fullCalendar('rerenderEvents');

I forgot to say... Everything happens okay without crashes... But nothing new in calendar. Thanks!

Answers


I corrected your code from above. Take a look at this:

var eventsArray = [];
var newEvent = [];

newEvent[0] = "some text";
newEvent[1] = new Date(y, m, d); //got date string here exactly similar to the calendar's
eventsArray.push(newEvent);

var formattedEventData = [];
for (var k = 0; k < eventsArray.length; k++) {
    formattedEventData.push({
        title: eventsArray[k][0],
        start: eventsArray[k][1]
    });
}

$('#calendar').fullCalendar({
    //eventsource: formattedEventData,
    events: formattedEventData,
    color: 'yellow',
    textColor: 'black'
});
//$('#calendar').fullCalendar('addEventSource', formattedEventData);
//$('#calendar').fullCalendar('rerenderEvents');

Few points to note here:

  1. If you want the newEvent to be an object, use this to create it: var newEvent = {title:"some text", start:new Date(y, m, d)};
  2. You can't initialize an array as newEvent[title]. Arrays are integer index based.
  3. eventSources and events can't be used together. If you have multiple event sources, then you need to include the events array inside your eventSources:

    eventSources: [ { events: [ { ... } ] } ]


See this: http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/

You can use it like this:

var newEvent = new Object();

newEvent.title = "some text";
newEvent.start = new Date();
newEvent.allDay = false;
$('#calendar').fullCalendar( 'renderEvent', newEvent );

Please note that when you assign value to start it needs to be in one of the supported formats.

You may specify a string in IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST"), a string in ISO8601 format (ex: "2009-11-05T13:15:30Z") or a UNIX timestamp.

Hope this helps. Thanks


Need Your Help

Specified cast is not valid - DataGridView

c# .net datagridview

I'm building an application and I'm using a .dll that requires a param "Level" to be set to either gold, silver or bronze. Level is a public enum Level in the .dll.

How to get TeamCity working with ASP.NET MVC 3 web project

asp.net-mvc asp.net-mvc-3 continuous-integration teamcity

I'm currently slugging it out with TeamCity trying to get two build configuration working for an ASP.NET MVC 3 solution. My setup is pretty much identical to the guidance at http://www.troyhunt.co...