【问题标题】:getting value and id from a React MaterialUI RadioButtonGroup从 React MaterialUI RadioButtonGroup 获取值和 id
【发布时间】:2017-08-21 09:27:33
【问题描述】:

我正在尝试从动态 MaterialUI RadioButtonGroup 中获取选定的 valuegameID

这样做我可以得到gameID,但不能得到value

<form onSubmit={this.handleEmailNotifications}>
    <ul>
        {profile.games.map((game) => {
            return (
                <li key={game.game_id}>
                    <RadioButtonGroup
                        name={game.game_title}
                        onChange={() => this.handleGameNewsChange(event, value, game)}>
                        <RadioButton
                            value="yes"
                            label="Yes"
                        />
                        <RadioButton
                            value="no"
                            label="No"
                        />
                    </RadioButtonGroup>
                </li>
            )
        })}
    </ul>
</form>


handleGameNewsChange(event, value, game) {
    console.log(event, value, game)
} 
//output undefinded, undefined, game

改变

onChange={() => this.handleGameNewsChange(event, value, game)}

onChange={this.handleGameNewsChange}>

我可以得到value,但不能得到gameID

我怎样才能两者兼得?

【问题讨论】:

    标签: javascript reactjs material-ui


    【解决方案1】:

    因为你没有在arrow function中传递eventvalue,所以这样写:

    onChange={(event, value) => this.handleGameNewsChange(event, value, game)}>
    

    这就是 eventvalue 未定义的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 2020-03-24
      • 1970-01-01
      • 2022-01-19
      • 2021-08-25
      • 1970-01-01
      • 2022-06-23
      相关资源
      最近更新 更多