开发者

Adding new data to Jquery after clicking a div

Here is a code of FullCalendar that I am using:

$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'agendaWeek,agendaDay'
        },
        editable: true,
        events: [
            {
                title: 'All Day Event',
                start: new Date(y, m, 1),
            },
            {
                title: 'Long Event',
                start: new Date(y, m, d-5),
                end: new Date(y, m, d-2)
            }
        ]
    });
});

I have a <a> element in the page and when I click on that link, I need to add following data to event of the calendar and the event should be became like this

events: [
    {
        title: 'All Day Event',
        start: new Date(y, m, 1),
    },
    {
        title: 'Meet Thomas Antony',
        start: new Date(y, m, 1),
    },
    {
        title: 'Meet Mathew',
        start: new Date(y, m, 1),
    },
    {
        title: 'Long Event',
        start: new Date(y, m, d-5),
        end: new Date(y, m, d-2)
    }
]

Which means this...:

{
    title: 'Meet Thomas Antony',
    start: new Date(y, m, 1),
},
{
    title: 'Meet Mathew',
    start: new Date(y, m, 1),
},

... should be added to events at the time of clicking a link tag. How ca开发者_JS百科n I do that?


There's a renderEvent method in fullCalendar for this:

$('#calendar').fullCalendar('renderEvent', {
  title: 'Meet Thomas Antony',
  start: new Date(y, m, 1)
}, true).fullCalendar('addEvent', {
  title: 'Meet Mathew',
  start: new Date(y, m, 1)
}, true);

In a full example you'd be looping though a collection, but you get the idea, just call .fullCalendar('renderEvent', eventObject, true). For a full event object property listing, look here. The last parameter is optional, depending of if you refresh the event data source later...if you want it to say in that case, set it to true, otherwise you can leave it off.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜