【发布时间】:2019-12-13 19:37:57
【问题描述】:
我是 Node/Webpack/React 的新手。当我在月/周/日视图之间切换时,应用程序经常崩溃,并且我在控制台中收到此错误:index.js?07ad:209 Uncaught TypeError: date[("get" + method)] is not a function。
请帮帮我,谢谢
代码
<MyCalendar
popup
selectable
localizer={localizer}
defaultView={[MyCalendar.Views.WEEK ]}
components={{toolbar: CustomToolbar}}
views={['week']}
style={{height: 600}}
events={this.props.events}
eventPropGetter={(this.eventStyleGetter)}
onSelectEvent={(slotInfo) => this.onSelectEventHandler(slotInfo)}
onSelectSlot={(slotInfo) => this.onSelectEventSlotHandler(slotInfo)}
/>
功能
function createAccessor(method) {
return function (date, val) {
if (val === undefined) return date['get' + method]();
date = new Date(date);
date['set' + method](val);
return date;
};
}
【问题讨论】:
-
你必须发布崩溃的功能
-
@Andrea-codemillers.com 请检查问题,我刚刚更新了我的问题并添加了功能
-
'get' + method的组合没有从date<Array>返回有效的函数,这就是导致错误的原因。 -
您可以通过
console.log对date和method进行调试,这将使您了解其中哪些给出了错误的值。 -
@SultanH。你能帮我解决这个问题吗
标签: javascript reactjs ecmascript-6 react-big-calendar