如何调整FullCalendar事件显示顺序:标题前置时间?(指定代码段修改)
Fixing FullCalendar Event Display: Title First, Time Second
Got it, let's adjust that event text order so your "7a Birthday Party" becomes "Birthday Party 7a". Here's exactly how to tweak the code in lines 14475-14495 of fullcalendar.js:
Step 1: Locate the Text Concatenation Logic
First, find the section in those lines where the event time and title are being stitched together. It’ll look something like this (varies slightly by FullCalendar version, but the core idea is the same):
// Original code (example from your target line range) var timeStr = this.formatTime(event.start, event.end, this.opt('timeFormat')); var titleStr = event.title || ''; var displayText = timeStr + ' ' + titleStr; // Time first, title second // Then this displayText gets inserted into the event element $(eventEl).html(displayText);
Step 2: Swap the Order of Title and Time
All you need to do is reverse the order of the variables in the concatenation line. Also, add a quick check to avoid extra spaces if the event has no title:
// Modified code var timeStr = this.formatTime(event.start, event.end, this.opt('timeFormat')); var titleStr = event.title || ''; // Swap title and time, handle empty title case var displayText = titleStr ? (titleStr + ' ' + timeStr) : timeStr; // Keep the DOM insertion line the same $(eventEl).html(displayText);
Quick Notes
- If your exact code uses different variable names (like
eventTextinstead ofdisplayText), just adjust to match what’s in your file—look for where the time string and title string are combined. - Double-check that you’re modifying the right block: it should reference
event.titleandformatTime/timeFormat, since those are the pieces we’re reordering.
内容的提问来源于stack exchange,提问作者user51395rk
相关产品推荐
相关产品推荐

