gpt4 book ai didi

javascript - Ant Design 中的Rangepicker 的值如何获取?

转载 作者:行者123 更新时间:2023-12-02 23:48:06 24 4
gpt4 key购买 nike

我有一个日期和时间的范围选择器表,该表是动态的,我可以添加和删除这些范围选择器,如下图所示: enter image description here

我想将这些值存储在另一个表上以将其发送到后端,当我在范围选择器上有值时,我收到错误。

我的代码是:

import { DatePicker } from 'antd';
import moment from 'moment-timezone';
import fr_FR from 'antd/lib/locale-provider/fr_FR';
import "moment/locale/fr";
const { RangePicker } = DatePicker;
export default class App extends Component {
constructor(props) {
super(props);
this.state= {
tranches :[{date:null}]
}
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString)
}
onOk(value) {
console.log('onOk: ', value);
}
render() {
return (
<div>
{
this.state.tranches.map((el, i) =>
<Row key={i}>
<Col span={12}>
&nbsp; &nbsp; &nbsp;
<label className="pt-label .modifier"><strong>Période</strong></label>
<LocaleProvider locale={fr_FR}>
<RangePicker
allowClear={false}
id="date" name= "date"
style={{ width: '547px', marginLeft:'20px'}}
locale="fr"
//placeholder={["Date de début","Date de fin"]}
separator="-"
onChange={this.onChange}
showTime={{ format: 'HH:mm' }}
format="DD/MM/YYYY HH:mm"
placeholder={['Date et heure de début', 'Date et heure de fin']}
onOk={this.onOk}
/>
</LocaleProvider>
</Col>
<Col span={12}>
{i === 0 ?
<>
<Icon type="plus-circle" theme="twoTone" twoToneColor="#52c41a" onClick={this.ajouterTranche}/>
<br/>
</>
:
<>
<Icon type="close-circle" theme="twoTone" twoToneColor="red" onClick={this.supprimerTranche(i)}/>

<Icon type="plus-circle" theme="twoTone" twoToneColor="#52c41a" onClick={this.ajouterTranche}/>
<br/>
</>
}
</Col>
</Row>
)}
}

我该如何修复它?

最佳答案

改变

onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString)
}

onChange = (value, dateString) => {
let date = this.state.date
date.push(value)
this.setState({date: date})
}

链接 herex 图标在上面的链接中不起作用

关于javascript - Ant Design 中的Rangepicker 的值如何获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55763038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com