本文介绍了使用反应组件时间选择器时,value.format 不是功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我尝试使用 timepicker 来更改某些值,例如
I try to use timepicker to change some value like
shutdown:{
Sunday : "18:00:00"
Monday : "20:00:00",
}
handleTimeChange(name, value){
var shut = this.state.shutdown;
shut[name] = value && value.format("HH:mm:ss");
console.log(value && value.format("HH:mm:ss"));
this.setState({
shutdown : shut
})
}
<TimePicker value={this.state.shutdown.Monday} onChange = {this.handleTimeChange.bind(this,"Monday")} />
但我收到错误:value.format 不是函数
But I got error : value.format is not a function
我该如何解决这个问题
参考 https://github/react-component/time-picker/blob/master/examples/value-and-defaultValue.js
推荐答案
React 总是将事件对象传递给事件处理程序.所以你可以使用事件对象来访问值.
React passes the event object to the event handler always. So you can use the event object to access the value.
将您的代码更改为:
handleTimeChange(name,event){
var value = event.target.value;
.....
}
这里,在你的情况下,名称是星期一"(事件处理程序的参数)
Here, name is "Monday" in your case(the parameter to the event handler)
这篇关于使用反应组件时间选择器时,value.format 不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论