2017-08-15 7 views
0

私の職場では、複数の場所で使用されているコンポーネントの中でSelectFieldを使用しています。意味をなさない今、私が作業している現在のコンポーネントの中でそのコンポーネントを使用するとき。私が作成したonChangeイベントは、正しく完了するために必要な値を渡しません。今度は、SelectFieldをonChange = {onChange}に変更するとうまく動作します。しかし、アプリ内の他の部分が依存しているので、このように設定することはできません。私はReactを初めて使う人です。ここで私は、インポートおよびコンポーネントここonChange In SelectableField Component for Material-UI/Reactが親からonChangeを受け入れていないコンポーネント

<CompanySelectField 
    label={translations.translate('driverProperties', 'typeOfVehicle')} 
    hint={translations.translate('driverProfile', 'pleaseSelectRole')} 
    style={{ marginTop: '25px' }} 
    name={'roles'} 
    value={this.state.history.roles} 
    onChange={this.addHistory('roles')} 
    fullWidth 
    required 
    > 

を使用していますCompanySelectFieldここに私の機能

addHistory = (field) => (event, index, value, target) => { 
    const { history } = this.state; 
    console.log(this.state.history); 
    console.log(field); 
    if (field === 'employerName' || field === 'description') { 
     history[field] = event.target.value; 
    } else if (field === 'roles') { 
     history[field] = value; 
    } else { 
     history[field] = event.value; 
    } 
    this.setState({ 
     history: this.state.history, 
    }); 
    } 

されている

<SelectField 
    name={name} 
    maxHeight={300} 
    value={value} 
    onChange={(event, index, response) => onChange(response)} 
    disabled={disabled} 
    hintText={hint} 
    > 

は前もってありがとうCompanySelectFieldそのものです。

+0

あなたが正しくあなたを理解していれば、SelectFieldのonChange小道具を変更すると問題は解決します。=>(イベント、インデックス、レスポンス)=> onChange(イベント、インデックス、レスポンス)} –

+0

パーフェクト、ありがとう –

答えて

0

addHistoryから返すメソッドには4つの引数、すなわちevent, index, value, targetがありますが、SelectFieldコンポーネントから呼び出すものはonChange={(event, index, response) => onChange(response)}です。これは引数が1つしかなく、上記の最初の引数と一致しない応答もあります。返されたメソッド。

+0

ありがとう完璧な意味合いがあり、私はそれを拾っていないために馬鹿だと感じる。答えてくれてありがとう。 –

+0

probsはありません...喜びは私のものでした –

関連する問題