【发布时间】:2021-12-13 15:46:24
【问题描述】:
我正在尝试这样做,以便当我的程序从假期 API 接收到新的 JSON 数据时,它可以用新数据替换来自 API 的旧数据。
我尝试在开始时将数组声明为空,但这不起作用。如果数组 > 1,我也尝试清空数组,但这也不起作用。
我的代码:
// Declares an empty array
var eventsArr = [];
console.log(eventsArr);
// Pushes the API data to an object
for(i = 0; i < result['data']['holidays'].length; i++){
let date = result['data']['holidays'][i]['date']['iso'];
eventsArr.push({
"startDate": new Date(date),
"endDate" : new Date(date),
"summary" : result['data']['holidays'][i]['description']
});
}
// Uses the pushed data to add the dates to the calendar
$("#calendar").simpleCalendar({
// Events displayed
displayEvent:true,
// Dates of the events
events: eventsArr
});
【问题讨论】:
-
您使用哪些库?我看到了 Jquery 和日历的东西。
-
我正在使用 jQuery 和这个日历:jqueryscript.net/time-clock/animated-event-calendar.html
-
事件加载正确一次但不是两次?
-
是的,它们第一次加载正确,但第二次没有替换。第一个只是留在日历上。
标签: javascript jquery arrays object calendar