Lam*_*zio 5 javascript fullcalendar cordova ionic-framework fullcalendar-3
我正在 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");
}
},
});
Run Code Online (Sandbox Code Playgroud)
我在输出中出现运行时错误:
date.getDate() 不是函数。(在“date.getDate()”中,“date.getDate()”未定义)Ionic 3 中的 FullCalendar
所以我不明白为什么,因为日期是一个已在 FullCalendar 库中定义的日期对象。
有什么解决方案吗?
ps:抱歉我的英语不好。
https://fullcalendar.io/docs/v3/dayRenderdayRender上的回调文档说
date是给定日期的时刻。
所以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");
}
},
//...
});
Run Code Online (Sandbox Code Playgroud)
有关我编写的代码的更多详细信息,请参阅http://momentjs.com/docs/#/parsing/string/了解 moment 构造函数可以解析的日期的详细信息,以及http://momentjs.com/docs /#/query/is-same/了解日期比较方法的详细信息。
您可以在此处查看上述内容的工作示例:http ://jsfiddle.net/sbxpv25p/22/
| 归档时间: |
|
| 查看次数: |
26345 次 |
| 最近记录: |