开发者

Adding options with an Array

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.


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


Have you tried something like that?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜