【问题标题】:Material-ui FormControlLabel value is not reflecting the changes when updating the stateMaterial-ui FormControlLabel 值不反映更新状态时的变化
【发布时间】:2019-10-12 23:00:45
【问题描述】:

我正在开发一个问答应用程序,该应用程序具有一个功能,当用户返回上一个问题时,他应该能够看到他/她以前的答案。因此,在一个组件中,我通过循环选择以单选按钮的形式向用户显示选项。我将用户当前的答案保存在 redux 商店的数组中。因此,当用户返回上一个问题时,我会获取他/她的最后一个答案并更新 componentDidUpdate() 中的 RadioGroup 值,但它不会更新 FormControlLabel 检查。

            <FormControl component="fieldset">
                <RadioGroup
                  aria-label="position"
                  name="position"
                  value={this.state.answers}
                  onChange={this.handleChange}
                >
                  {this.state.currentChoices.map(choice => (
                    <FormControlLabel
                      value={choice.label}
                      control={<Radio color="primary" />}
                      label={choice.label}
                      labelPlacement="end"
                      key={choice.label}
                    />
                  ))}
                </RadioGroup>
              </FormControl>

我控制 RadioGroup 的值(即:this.state.answers)它正在更新但 FormControlLabel 没有得到检查

【问题讨论】:

    标签: reactjs material-ui radio-group


    【解决方案1】:

    只需确保数据类型正确即可。 FormControlLabel 的值通常会转换为字符串。现在遇到了同样的问题。

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 2023-03-20
      • 2021-04-11
      • 1970-01-01
      相关资源
      最近更新 更多