0
私はmaterialuiのDatePickerコンポーネントを使用しています.2つのDatePickerコンポーネントの値を1つの関数で取得して範囲を作成する必要があります。onChange(ReactJS)のコンポジットdatepicker 2の値を取得
私は、すでにDatePickerコンポーネントの値を取得することができるhandleChange関数を作成しましたが、2つのコンポーネントではそれを行うことはできません。
私は必要な手順を知りたいと思います。
これは私のコードです:
import React from 'react';
import moment from 'moment';
import 'moment/locale/fr'
import DatePicker from 'material-ui/DatePicker';
import areIntlLocalesSupported from 'intl-locales-supported';
let DateTimeFormat;
if (areIntlLocalesSupported(['fr'])) {
DateTimeFormat = global.Intl.DateTimeFormat;
} else {
const IntlPolyfill = require('intl');
DateTimeFormat = IntlPolyfill.DateTimeFormat;
require('intl/locale-data/jsonp/fr');
require('intl/locale-data/jsonp/fa-IR');
}
class SearchByDate extends React.Component {
handleSearchByDate = (evt, date) => {
console.log(date)
}
render() {
return (
<div>
<DatePicker
ref="dateChoiceOne"
name="dateChoiceOne"
hintText="Date début"
DateTimeFormat={DateTimeFormat}
okLabel="OK"
cancelLabel="Annuler"
locale="fr"
onChange={this.handleSearchByDate}/>
<DatePicker
ref="dateChoiceTwo"
name="dateChoiceTwo"
hintText="Date fin"
DateTimeFormat={DateTimeFormat}
okLabel="OK"
cancelLabel="Annuler"
locale="fr"
onChange={this.handleSearchByDate} />
</div>
)
}
}
export default SearchByDate;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
てみロギング 'evt.target.name'内部' handleSearchByDate' – anand
@anand私が試したが、それは動作しません。また、DatePickerコンポーネントのMaterial UIドキュメントを読むと、onChangeプロパティが呼び出す関数の「イベント」パラメータがnullを返すことがわかりました。 (http://www.material-ui.com/#/components/date-picker)=>署名: 関数(null:未定義、日付:オブジェクト)=> void null:関連する特定のイベントがないため変更すると、最初の引数は常にnullになります。 date:新しい日付。 –