【发布时间】:2017-08-30 19:46:03
【问题描述】:
我在 ReactJs 组件上使用 jQuery fullcalendar。
我在渲染方法上有一个<div id="calendar"></div>
在 componentDidUpdate 上,我使用以下代码更新了日历:
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: _this.state.events,
defaultView:'month',
displayEventTime: false,
editable: false,
droppable: false,
durationEditable: false
});
它在标题上显示“未定义”字符。 我哪里做错了? 以及如何调试未定义字符串的来源?
目前, 我做了一个破解的解决方案,通过添加以下内容从标题中删除所有未定义的字符串:
viewRender: function(view, element) {
//note: this is a hack, i don't know why the view title keep showing "undefined" text in it.
//probably bugs in jquery fullcalendar
$('.fc-center')[0].children[0].innerText = view.title.replace(new RegExp("undefined", 'g'), ""); ;
},
有没有更好的办法?
我正在使用 jquery FullCalendar v2.9.1
使用以下事件示例数据:
[{"start":"2017-03-24T00:00:00.000Z","end":"2017-03-26T00:00:00.000Z","title":"Open house","description":"Bali 1 open house"}]
注意:我最终放弃了 jquery 完整日历,转而使用 react-big-calendar。
【问题讨论】:
-
出现此未定义消息时,您是否在浏览器控制台中收到任何错误?你有没有在任何地方设置titleFormat? fullcalendar.io/docs/text/titleFormat 如果这样做,请确保您指定的格式有效。
-
控制台上没有错误。它是一个小组件。我只用它来显示日历,所以标题格式仍然没有..我尝试将其设置为 titleFormat: 'MMMM YYYY' ,但没有运气.. 不知道如何调试标题。
-
如果你在 ReactJS 上下文之外使用它可以正常工作吗?
-
应该没问题,因为jquery日历是react渲染后更新的。还尝试将其放在 componentDidMount 上。没有运气。真的没有办法调试jquery吗?
-
您可以使用浏览器的开发工具调试页面上的任何脚本。它可能是你想要调试的 fullCalendar 。显然,如果您拥有脚本的非缩小版本,它会更容易。我会先在 ReactJS 上下文之外尝试它,然后你可以排除/排除 React 是否以某种方式干扰它。
标签: javascript jquery reactjs fullcalendar jsx