4Manuals

  • PDF Cloud HOME

如何在reactjs中更新值 Download

    反应:更改方向后触发重新渲染和offsetWidth的重新计算 如何在react图表上的datakey中操作DateTime 如何在nextjs中使用html2canvas 使用一些Typescript文件测试React应用 React-native动画时间序列及其百分比或替代 谁能帮助我通过wordpress登录和注册来创建React Native应用? 如何检查电子屏幕截图的允许状态(macOS catalina) 时间戳格式不支持将React`react-datepicker`作为默认值 我正在尝试将nextjs应用程序构建到静态html页面中,我有一些错误 应对延迟加载:如何控制切入块的内容

    constructor(props) {
        super(props)

        this.state = {
            isEdit: false,
            currentProduct : {
                sku: '',
                productName: '',
                description: '',
                duration: '',
            },
        }       
    }    

handleChange = (e) => {
            this.setState({
              currentProduct: {
               ...this.state.currentProduct,
               [e.target.name]: e.target.value
              }
          })
       }

    clickHandle = (e) => {
        e.preventDefault()
        const currentProduct = {...this.state.currentProduct}
        currentProduct.id = this.props.match.params.id

        this.props.updateProduct(currentProduct)
        this.props.history.push('/')
    }

当更新字段时,它会更新值,但是当我再次更新单个值时,它只会更新并删除另一个不知道为什么的

2 个答案:

答案 0 :(得分:2)

handleChange = (e) => {
        this.setState({
           ...this.state.currentProduct,
           [e.target.name]: e.target.value
      })
   }

答案 1 :(得分:0)

您并没有首先破坏整个状态。也是如此。否则isEdit字段将丢失。

  handleChange = e => {
    this.setState({
      ...this.state,
      currentProduct: {
        ...this.state.currentProduct,
        [e.target.name]: e.target.value
      }
    });
  };



Similar searches
    如何从Oracle LISTAGG聚合查询的结果中消除重新填充的值 适用于GPU的Python编码 SetFocus是功能吗? 未指定自定义帖子时显示自定义帖子存档 为什么当我按下登录按钮时我的消息框不会显示