2017-12-19 10 views
0

値を返すことに若干の問題があります。javascriptエラー:これは機能ではありません

だから私は、現在のプロジェクトを反応させて、次のようにあるコンポーネント持っている次のようにそれはoverdue = {CheckingStatus.overdueCalculation(booking.bookingEnd)}

でCheckingStatus.jsを失敗し続けるしかし

<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> 

は次のとおりです。

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 
    } 
} 

アイデア

答えて

2

延滞計算方法shou静的メソッドとして宣言します。例:

export default class overdueChecker { 
    static overdueCalculation = (bookingEnd) => { 
     // method body 
    } 
} 
+0

同じ問題。 checkingStatus __。a.overdueCalculationは関数ではありません。エラーが発生しました –

+0

インポートでエラーが発生しました。これは実際に働いた –

関連する問題