Javascript FullCalendar 自定义标题标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7412615/
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
FullCalendar custom header title
提问by emma
I need to show a custom header title in the calendar. I am handling 16 calendars and I need every one of them to show their own title. I have tried everything I could modifying this part of the code:
我需要在日历中显示自定义标题。我正在处理 16 个日历,我需要每个日历都显示自己的标题。我已经尝试了所有可以修改这部分代码的方法:
firstDay: <?php echo $iFirstDay; ?>,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
But everytime I edit the center
to add something else apart from the title
my calendar doesn't show any title at all. What should I do?
但是每次我编辑center
除了title
日历之外的其他内容时,它根本不显示任何标题。我该怎么办?
回答by Dionys
If you are using fullCalender v2you will have to escape string by putting them between scare brackets. This is because of the moment.js library (see the moment doc).
如果您使用fullCalender v2,则必须将字符串放在括号之间来转义字符串。这是因为 moment.js 库(请参阅 moment doc)。
So that would be
所以那将是
firstDay: <?php echo $iFirstDay; ?>,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
titleFormat: '[Hello, World!]',
回答by Brandon
You don't change the center
attribute. That just specifies what gets placed in the center of the header.
你不改变center
属性。这只是指定放置在标题中心的内容。
If you want to change the contents of the title itself, you need to change the titleFormat.
如果要更改标题本身的内容,则需要更改titleFormat。
firstDay: <?php echo $iFirstDay; ?>,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
titleFormat: '\'Hello, World!\'',
titleFormat
uses a formatted date as the value, so if you want to display literal text, you need to wrap it in single quotes, but just remember to escape them.
titleFormat
使用格式化的日期作为值,所以如果你想显示文字文本,你需要用单引号将它括起来,但记住要转义它们。
回答by sukebe7
you can just poke the name in before the calendar gets rendered, or even at the very top of the page:
您可以在日历呈现之前插入名称,甚至在页面的最顶部:
<?php
echo "<center><h1>$fullname</h1></center>";
?>
Ugly, but works.
丑陋,但有效。
回答by noomz
You can try this. I use this to hack Buddhist era display:
你可以试试这个。我用它来破解佛教时代的显示:
const computeTitle = FullCalendar.View.prototype.computeTitle;
FullCalendar.View.prototype.computeTitle = function (dateProfile) {
const $ = jQuery;
if (dateProfile.currentRangeUnit === 'month') {
const cal = jQuery(".js-drupal-fullcalendar").fullCalendar('getCalendar');
const era = cal.moment(dateProfile.date).year() + 543;
return cal.moment(dateProfile.date).format('MMMM') + ' ' + era;
}
return computeTitle(dateProfile);
};
P.S: This pull request is seem to stale: https://github.com/fullcalendar/fullcalendar/pull/3532
PS:这个拉取请求似乎过时了:https: //github.com/fullcalendar/fullcalendar/pull/3532