我正在尝试从动态 MaterialUI RadioButtonGroup 中获取选定的值
和gameID
。
Doing it like this i can get the
gameID
, but not thevalue
:
<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}>
I can get the
value
but not thegameID
我怎样才能同时获得两者?
最佳答案
因为您没有在arrow function中传递事件
和值
,这样写:
onChange={(event, value) => this.handleGameNewsChange(event, value, game)}>
这就是事件
和值
未定义的原因。
关于javascript - 从 React MaterialUI RadioButtonGroup 获取值和 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45793615/