1

I'm using the fullCalendar jQuery plugin and it has options for adding events to the calendar as such:

$('#calendar').fullCalendar({
    editable: false,
    events: [
        {
            title: 'Just some random event',
            start: '2011-04-30'
        },
        {
            title: 'Long Event',
            start: '2011-05-01'
        }
    ]
});

I'm trying to implement this into a Drupal 7 view. I will have loop through a list of elements and grab the hidden timestamp to populate the calendar. I know how to loop through the elements and grab the values, but I'm not sure how to add the values to an array I could use to populate the events option.

2 Answers 2

1

Create an empty array:

var events = [];

Then you can add objects to it in your loop:

var title = "Just some random event";
var start = "2011-04-30";
events.push({ title: title, start: start });

Now you can use the array in the calendar:

$('#calendar').fullCalendar({
  editable: false,
  events: events
});
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried something like that?

var yourEventsArray = [];
$.each(data, function(index, value) {
    yourEventsArray.push({
      title: value.title,
      start: value.timeStamp
    });
});

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.