返回值时遇到轻微问题。
所以我目前有一个反应项目,并有一个如下组件:
<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
}
}
任何想法
答案 0 :(得分:2)
overdueCalculation方法应声明为静态方法。例如
export default class overdueChecker {
static overdueCalculation = (bookingEnd) => {
// method body
}
}