基本上任何硬编码的值都可以工作。但是,当我构建一个偶数对象数组然后设置它时,日历中不会添加任何事件。
function getCalendarEvents() {
var events = new Array();
$(".ms-srch-item:visible").each(function () {
events.push(
{
title: $(this).find(".assigned_resource").html(),
start: new Date($(this).find(".start_date").attr("date")),
end: new Date($(this).find(".end_date").attr("date"))
});
});
return events;
}
$(document).ready(function () {
$("#testme").click(function () {
var array = [{ title: 'All Day Event', start: new Date(2013, 8, 5) }];
array = getCalendarEvents();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek'
},
events:array
});
$(".fc-button-agendaWeek").click(function () {
$(".fc-agenda-allday").next().next().hide();
});
});
});
我检查了数组对象,它的格式正确且值正确。但由于某种原因,我没有收到任何事件。如果我不使用该功能并使用硬编码,它适用于该事件。看到我的代码有任何问题吗?
编辑:
这是工作代码(忽略我添加的颜色内容):
function getCalendarEvents() {
if(calendarColors.length < 1)
{
//build colors first time ...do it here because we want to wait for async clients call to finish
BuildCalendarColorsMap();
}
var events = new Array();
$(".ms-srch-item:visible").each(function () {
var client = $(this).find(".client").html();
//junk check testing
if (client && client.indexOf('<strong>Client:</strong>') != -1) {
client = client.replace('<strong>Client:</strong>', '');
var start = new Date($(this).find(".start_date").attr("date"));
var end = new Date($(this).find(".end_date").attr("date"));
var title = client + ": " + $(this).find(".assigned_resource").html().replace('<strong>Assigned Resource:</strong>', "");
var color = getCalendarColor(client);
events.push(
{
title: title,
start: new Date(start.getFullYear(), start.getMonth(), start.getDate()),
end: new Date(end.getFullYear(), end.getMonth(), end.getDate()),
color: color
});
}
});
return events;
}