javascript date.getDate() 不是函数。(在“date.getDate()”中,“date.getDate()”未定义)Ionic 3 中的 FullCalendar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46279355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
date.getDate() is not a function. (In 'date.getDate()', 'date.getDate()' is undefined) FullCalendar in Ionic 3
提问by Lamoichenzio
I'm coding on a Ionic 3 project where i use a FullCalendar plugin for display a calendar ui. I've a problem with this code in the module of page when i try to change background of a single day on calendar. I've used dayRender function of FullCalendar.
我正在编写一个 Ionic 3 项目,我使用 FullCalendar 插件来显示日历 ui。当我尝试更改日历上某一天的背景时,页面模块中的此代码出现问题。我使用了 FullCalendar 的 dayRender 函数。
$('#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");
}
},
});
I've this Runtime error in output:
我在输出中有这个运行时错误:
date.getDate() is not a function. (In 'date.getDate()', 'date.getDate()' is undefined) FullCalendar in Ionic 3
date.getDate() 不是函数。(在“date.getDate()”中,“date.getDate()”未定义)Ionic 3 中的 FullCalendar
so i don't understand why, because date is a Date object that was already defined in FullCalendar library.
所以我不明白为什么,因为 date 是一个已经在 FullCalendar 库中定义的 Date 对象。
Any Solutions?
任何解决方案?
ps: Sorry for my bad english.
ps:抱歉我的英语不好。
采纳答案by ADyson
The documentation of the dayRendercallback at https://fullcalendar.io/docs/display/dayRender/says
https://fullcalendar.io/docs/display/dayRender/上的dayRender回调文档说
dateis the Momentfor the given day.
date是给定日期的时刻。
So datein your code is a momentJS object, not a Date object. That's why the getDate method doesn't exist on it. You'd be better to create todayas a momentJS object too, and then you can compare them directly:
所以date在你的代码中是一个 momentJS 对象,而不是一个 Date 对象。这就是为什么 getDate 方法不存在的原因。你最好也创建today一个momentJS对象,然后你可以直接比较它们:
$('#calendar').fullCalendar({
dayRender: function (date, cell) {
var today = moment('2017-09-11T00:00Z');
if (date.isSame(today, "day")) {
cell.css("background-color", "red");
}
},
//...
});
For more detailed info on the code I've written, see http://momentjs.com/docs/#/parsing/string/for details of dates that the moment constructor can parse, and http://momentjs.com/docs/#/query/is-same/for details of the date comparison method.
有关我编写的代码的更多详细信息,请参阅http://momentjs.com/docs/#/parsing/string/以了解 moment 构造函数可以解析的日期的详细信息,以及http://momentjs.com/docs /#/query/is-same/有关日期比较方法的详细信息。
You can see a working example of the above here: http://jsfiddle.net/sbxpv25p/22/
您可以在此处查看上述工作示例:http: //jsfiddle.net/sbxpv25p/22/

