gpt4 book ai didi

javascript - 在 dayclick 回调中访问 fullCalendar JSON customData

转载 作者:行者123 更新时间:2023-11-29 15:44:48 24 4
gpt4 key购买 nike

很抱歉这个最简单的问题。我想将一些自定义 JSON 数据添加到 fullCalendar 并在我的 dayClick 回调函数中使用它。更具体地说,我想在 dayClick 中访问和更改 customData 上的元素。但是我不知道该怎么做。不改fullcalendar源代码是否可行?

提前致谢延斯

$('#calendar').fullCalendar({
....
firstDay: 1,
customData: { foo: 'bar', more: 'baz' },
dayClick: function(date, allDay, jsEvent, view) {
// Within the callback function, this is set to the <td> of the clicked day.
var t = $(this);
var foo = customData.foo; // does not work
customData.more = 'foo'; // does not work

// Change the day's background color
if (t.hasClass('badge-important') && foo == 'bar') {
t.removeClass('badge-important');
} else {
t.addClass('badge-important');
}
},
});

最佳答案

问题是您没有在任何地方定义 customData 变量。以下创建变量来存储 JSON 的方法将解决您的问题。检查下面的代码:

var customData = {"foo":"bar"};

$('#calendar').fullCalendar({
....
firstDay: 1,
customData: customData,
dayClick: function(date, allDay, jsEvent, view) {
// Within the callback function, this is set to the <td> of the clicked day.
var t = $(this);
var foo = customData.foo; // will now work
customData.more = 'foo' // will work too

// Change the day's background color
if (t.hasClass('badge-important') && foo == 'bar') {
t.removeClass('badge-important');
} else {
t.addClass('badge-important');
}
},
});

希望对您有所帮助。干杯

关于javascript - 在 dayclick 回调中访问 fullCalendar JSON customData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13381992/

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