gpt4 book ai didi

javascript - fullCalendar 中的日期循环

转载 作者:行者123 更新时间:2023-12-01 01:36:03 24 4
gpt4 key购买 nike

This is how i want to display my dates in the calendar **我正在尝试使用 for 循环**将日期动态添加到 fullCalendar 中,这是我的代码

odoo.define('website_customs.calender', function(require) {
"use strict";


$(function() {

var value_1 = $('.passed_value').text();
var objectStringArray = (new Function("return [" + value_1+ "];")());
console.log(objectStringArray,objectStringArray[0])
var array=[]

for (var i in objectStringArray[0]){

array.push(objectStringArray[0][i])

}

console.log("array :", array) //["2018-9-24", "2018-9-26", "2018-9-25"]
console.log("array length",(array.length)); // 3


$('#calendar').fullCalendar({




for (var j = 0; j < array.length; j++) {
events:
[
{
title: 'Booked',
start: array[j]
},
],
}



eventRender: function (event, element, view) {
// event.start is already a moment.js object
// we can apply .format()
var dateString = event.start.format("YYYY-MM-DD");

$(view.el[0]).find('.fc-day[data-date=' + dateString + ']').css('background-color', '#b72727');
}

});

});
});

但是我收到错误Uncaught SyntaxError: Unexpected token var我尝试将循环放在事件之外,但仍然出现错误。

我应该尝试其他方法吗?有什么建议吗?

提前致谢。

最佳答案

这就是您的事件应该如何准备的。

odoo.define('website_customs.calender', function(require) {
"use strict";
$(function() {
var value_1 = $('.passed_value').text();
var objectStringArray = (new Function("return [" + value_1 + "];")());
console.log(objectStringArray, objectStringArray[0])
var array = [];

for (var i in objectStringArray[0]) {
array.push(objectStringArray[0][i])
}

console.log("array :", array) //["2018-9-24", "2018-9-26", "2018-9-25"]
console.log("array length", (array.length)); // 3

var eventsArray = []
for (var j = 0; j < array.length; j++) {
eventsArray.push({ title: 'Booked', start: array[j] });
}

$('#calendar').fullCalendar({
events: eventsArray,
eventRender: function(event, element, view) {
// event.start is already a moment.js object
// we can apply .format()
var dateString = event.start.format("YYYY-MM-DD");
$(view.el[0]).find('.fc-day[data-date=' + dateString + ']').css('background-color', '#b72727');
}
});
});
});

关于javascript - fullCalendar 中的日期循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52811287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com