在返回值时遇到一点问题。
因此,我目前有一个React项目,并且具有以下组件:
<List>
{bookings.map((booking) =>
<ListItem
onChange={onChange}
id={booking.bookingId}
overdue = {CheckingStatus.overdueCalculation(booking.bookingEnd)}
initial={booking.customer.initial.substring(0,1)+booking.customer.lastName.substring(0,1)}
name={booking.customer.initial +'. '+ booking.customer.lastName}
reference={'REF: '+booking.bookingReference}
setStyle={selected!=null && selected.id===booking.bookingId ? true : false}
/>
)}
</List>
但是,它总是在
overdue = {CheckingStatus.overdueCalculation(booking.bookingEnd)}
上失败CheckingStatus.js如下所示:
import moment from 'moment'
export default class overdueChecker {
static overdueCalculation = (bookingEnd) => {
//set 1 to grace period of next day 1am
var d1 = new Date()
d1.setDate(d1.getDate() + 1);
d1.setHours(1)
d1.setMinutes(0)
d1.setSeconds(0)
var d2 = new Date(bookingEnd)
//determine if overdue
if(d1.getTime()>d2.getTime()){
this.setState({warning : true})
} else {
this.setState({warning : false})
}
//calculate days overdue
var d1m = moment(d1)
var d2m = moment(d2)
var diff = d1m.diff(d2m,'days')
return diff
}
}
有任何想法吗
最佳答案
应该将overdueCalculation方法声明为静态方法。例如
export default class overdueChecker {
static overdueCalculation = (bookingEnd) => {
// method body
}
}