使用反应组件时间选择器时,value.format 不是功能

编程入门 行业动态 更新时间:2024-10-23 09:41:18
本文介绍了使用反应组件时间选择器时,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:关键词]

本文发布于:2023-04-30 11:38:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   功能   时间   选择器   format

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!