简体   繁体   English

从React MaterialUI RadioButtonGroup获取值和ID

[英]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获取选定的valuegameID

Doing it like this i can get the gameID , but not the value : 这样我可以得到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 the gameID 我可以获取value但不能获取gameID

How can i get both? 我怎样才能两者兼得?

Because you are not passing the event and value in arrow function , write it like this: 因为您没有在箭头函数中传递eventvalue ,所以请这样编写:

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

That's why event and value was undefined. 这就是为什么eventvalue未定义的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM