[英]Ant design: get Id from datepicker in onChange
I've a form with multiple Datepickers in a React-Redux app and I need to know the id of the Datepicker that has been used.我在 React-Redux 应用程序中有一个包含多个 Datepicker 的表单,我需要知道已使用的 Datepicker 的 ID。
When the datepickers are created I can assign a function to the onChange
method (this method has two params (dates) to use).创建日期选择器后,我可以为
onChange
方法分配一个函数(此方法有两个要使用的参数(日期))。
<DatePicker
title={field.title}
placeholder={field.title}
format={"YYYY/MM/DD"}
size={params.fieldsize}
onChange={this.handleDatePickerChange}
/>
I need to retrieve the id of the Datepicker inside the handleDatePickerChange
function:我需要在
handleDatePickerChange
函数中检索handleDatePickerChange
的 id:
handleDatePickerChange = (date, dateString) => {
// get the id
...
}
The (date, dateString) are the params of the returned callback function. (date, dateString) 是返回的回调函数的参数。 See method onChange in https://ant.design/components/date-picker/#DatePicker
参见https://ant.design/components/date-picker/#DatePicker 中的onChange 方法
A callback function, can be executed when the selected time is changing.
一个回调函数,可以在选择的时间改变时执行。
How can I do that?我怎样才能做到这一点?
You can send an extra variable in onChange
function as below:您可以在
onChange
函数中发送一个额外的变量,如下所示:
onChange={(date, dateString) => this.handleDatePickerChange(date, dateString, 1)}
And then in handleDatePickerChange
method you can get it as given below:然后在
handleDatePickerChange
方法中你可以得到它,如下所示:
handleDatePickerChange = (date, dateString, id) => {
console.log(id);
...
}
I have created a demo on codesandbox.io .我在codeandbox.io上创建了一个演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.