weekNumbers 选项在timelineYears 视图中似乎没有任何影响。我找到了一种在使用以下 JS 时添加周数的方法:
var headerRows = $(".fc-head .fc-time-area table tr");
if (headerRows.length == 2) {
var monthRow = headerRows[0];
var dayRow = headerRows[1];
$.ajax({
url: '@Url.Action("GetYearWeeks")',
type: "POST",
async: true,
cache: false,
dataType: "json",
success: function (response) {
var cells = $(dayRow).find("th")
//ADD WEEK ROW
var weekRow = $("<tr class='fc-week-header'></tr>")
$(dayRow).before(weekRow);
//ADD WEEK CELLS
var lastWeek = null
var currentCell = null
for (var i = 0; i < cells.length; i++) {
var cellDate = new Date($(cells[i]).data("date"))
var cellWeek = 1
for (var y = 0; y < response.length; y++) {
var startDate = new Date(parseInt(response[y].Start_Date.substr(6)))
var endDate = new Date(parseInt(response[y].End_Date.substr(6)))
startDate.setHours(0, 0, 0, 0)
endDate.setHours(0, 0, 0, 0)
if (startDate <= cellDate && endDate >= cellDate) {
var timeDiff = Math.abs(startDate.getTime() - cellDate.getTime());
var diffDays = timeDiff / (1000 * 3600 * 24);
cellWeek = Math.floor(diffDays / 7) + 1
break;
}
}
if (lastWeek != cellWeek) {
lastWeek = cellWeek
currentCell = $("<th>" + cellWeek + "</th>")
currentCell.data("date", cellDate)
weekRow.append(currentCell)
}
else {
var colSpan = currentCell.attr('colspan')
if (colSpan == null) {
colSpan = 1
}
colSpan++;
currentCell.text("Week " + cellWeek)
currentCell.attr('colspan', colSpan)
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
ShowErrorMessage("Error", errorThrown)
}
});
Web 方法 GetYearWeeks 返回具有以下属性的对象数组(VB.NET MVC):
Public Class YearWeeks
Public Property Year As Integer
Public Property Weeks_In_Year As Integer
Public Property Start_Date As DateTime
Public Property End_Date As DateTime
End Class