[英]getting value and id from a React MaterialUI RadioButtonGroup
I'm trying to get the selected value
and gameID
from a dynamic MaterialUI RadioButtonGroup. 我正在尝试从动态MaterialUI RadioButtonGroup获取选定的
value
和gameID
。
Doing it like this i can get the
gameID
, but not thevalue
:这样我可以得到
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
Changing from 从改变
onChange={() => this.handleGameNewsChange(event, value, game)}
to 至
onChange={this.handleGameNewsChange}>
I can get the
value
but not thegameID
我可以获取
value
但不能获取gameID
How can i get both? 我怎样才能两者兼得?
Because you are not passing the event
and value
in arrow function , write it like this: 因为您没有在箭头函数中传递
event
和value
,所以请这样编写:
onChange={(event, value) => this.handleGameNewsChange(event, value, game)}>
That's why event
and value
was undefined. 这就是为什么
event
和value
未定义的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.