我在一个离子3项目上编码,在该项目中,我使用FullCalendar插件来显示日历UI。当我尝试在日历上更改一天的背景时,我在页面模块中对此代码有问题。我使用了FullCalendar的日光函数。
$('#calendar').fullCalendar({
dayRender: function (date, cell) {
var today = new Date('2017-09-11T00:40Z')
if (date.getDate() == today.getDate()) {
this.cell.css("background-color", "red");
}
},
});
我在输出中有一个运行时错误:
date.getDate()不是函数。(在'date.getdate()'中, 'date.getDate()'是未定义的)Ionic 3
中的fullcalendar
所以我不明白为什么,因为日期是已在FullCalendar库中定义的日期对象。
有什么解决方案?
ps:对不起,我的英语不好。
https://fullcalendar.io/docs/v3/dayrender dayRender
回调的文档说
date
是给定日期的 moment 。
因此,您的代码中的date
是MONMJS对象,而不是日期对象。这就是为什么getdate方法不存在的原因。您最好也将today
作为MOMTJS对象创建,然后可以直接比较它们:
$('#calendar').fullCalendar({
dayRender: function (date, cell) {
var today = moment('2017-09-11T00:00Z');
if (date.isSame(today, "day")) {
cell.css("background-color", "red");
}
},
//...
});
有关我编写的代码的更多详细信息,请参见http://momentjs.com/docs/#/parsing/string/有关MONM构造器可以解析的日期的详细信息,以及http://mommentjs。com/doc/#/query/is-same/有关日期比较方法的详细信息。
您可以在此处看到以上的工作示例:http://jsfiddle.net/sbxpv25p/22/