提问人:Sephirah 提问时间:7/10/2023 最后编辑:freedomn-mSephirah 更新时间:7/10/2023 访问量:35
为什么我的jQuery日历无法正确显示
Why does my jQuery calendar not display correctly
问:
我有一些代码从数据库中收集数据,然后在数据库中关闭日期时为某个 div 提供特定的类 ()。fc-closedDay
代码的另一部分获取具有此特定类的 div,并使用 配置日历 () 的数据 (),以便日历在页面上正确显示。calendarAvailabilities
cal.setData
calendario
问题就在这里。数据被正确收集。我做了一个,这是显示的良好数据。有时,会出现一个错误:所有 div 都得到类。即使此错误未显示,日历也无法正确显示。当我更改日历的月份时,一次月份完全打开,另一次月份完全关闭,另一次关闭日是其他 2 个月数据的混合。console.log(data)
fc-closedDay
我已经有 3 周了,我一直在这个问题上,我不知道现在该怎么办。有人可以帮我吗?
以下是包含获取数据的部分、设置 div 的部分和设置 () 的部分的函数:getClosingDays
calendarAvailabilities
cal.setData
function getClosingDays(cal)
{
// Get closing days
jQuery.get( "index.php?option=com_skydivespa&task=reservation.getClosingDays", {"month": cal.getMonth(), "year": cal.getYear()},
function(data) {
console.log(data);
var periods = JSON.parse(data);
// console.log(periods['data'][0].mon);
if (periods['data'].length === 1) {
if (periods['data'][0].mon == 0) jQuery("span.fc-weekday:contains('Lun')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].tue == 0) jQuery("span.fc-weekday:contains('Mar')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].wed == 0) jQuery("span.fc-weekday:contains('Mer')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].thu == 0) jQuery("span.fc-weekday:contains('Jeu')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].fri == 0) jQuery("span.fc-weekday:contains('Ven')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].sat == 0) jQuery("span.fc-weekday:contains('Sam')").parent("div").addClass('fc-closedDay');
if (periods['data'][0].sun == 0) jQuery("span.fc-weekday:contains('Dim')").parent("div").addClass('fc-closedDay');
} else {
for (var i = 0; i < periods.data.length; i++) {
var dateStartPeriod = new Date(periods['data'][i].date_start);
var dateEndPeriod = new Date(periods['data'][i].date_end);
if ((periods['data'][i].mon == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Mon')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Mon')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].tue == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Tue')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Tue')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].wed == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Wed')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Wed')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].thu == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Thu')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Thu')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].fri == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Fri')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Fri')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].sat == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Sat')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Sat')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
if ((periods['data'][i].sun == 0)) {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Sun')").prev("span.fc-date:contains('" + d + "')").parent("div").addClass('fc-closedDay');
}
} else {
for (var d = (parseInt(dateStartPeriod.getDate())); d <= (parseInt(dateEndPeriod.getDate())); d++) {
jQuery("span.fc-weekday:contains('Sun')").prev("span.fc-date:contains('" + d + "')").parent("div").removeClass('fc-closedDay');
}
}
}
}
for (let d =1; d <= 31; d++)
{
let number = Intl.NumberFormat('en-US', {minimumIntegerDigits: 2});
let date = new Date(number.format(cal.getMonth())+"-" + number.format(d) + "-" + cal.getYear());
//let day = date.getDay();
if ($("span.fc-date:contains('" + d + "')").parent("div").hasClass('fc-closedDay'))
calendarAvailabilities[number.format(cal.getMonth())+"-" + number.format(d) + "-" + cal.getYear()] = ['<span class="close uk-button uk-button-small uk-button-primary uk-margin-small">Close</span>'];
else
calendarAvailabilities[number.format(cal.getMonth())+"-" + number.format(d) + "-" + cal.getYear()] = ['<span class="free uk-button uk-button-small uk-button-primary uk-margin-small" onclick="validateResaStep1(\'9:00\')" slot="9:00:00">9:00-10:00</span>'];
}
getOpenDays(cal);
});
}
我尝试了async await,setTimeout。不幸的是,一切都没有改变。我不知道我是否做了一个正确的异步等待。我没有尝试其他东西,因为我迷路了。
答: 暂无答案
评论
span.fc-date:contains('" + d + "')")
d
"1"
:contains-exact
date
let date = new Date(number.format(cal.getMonth())
let date = new Date(number.format(cal.getMonth()+1)
calendarAvailabilities[number.format(cal.getMonth())+
.getMonth()