0

想知道我是如何创建一个对象并用信息填充他的,这样我就可以将他添加到完整的日历 jquery 插件中。到目前为止,我做了类似的事情:

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

我忘了说......一切都很好,没有崩溃......但日历中没有什么新鲜事。谢谢!

4

2 回答 2

1

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: [ { ... } ] } ]

于 2012-06-18T13:31:34.767 回答
1

看到这个: http ://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/

你可以像这样使用它:

var newEvent = new Object();

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

请注意,当您分配值时开始,它需要采用受支持的格式之一。

您可以指定 IETF 格式的字符串(例如:“Wed, 18 Oct 2009 13:00:00 EST”)、ISO8601 格式的字符串(例如:“2009-11-05T13:15:30Z”)或 UNIX 时间戳.

希望这可以帮助。谢谢

于 2012-06-29T21:45:43.110 回答