javascript - 从 React MaterialUI RadioButtonGroup 获取值和 id

标签 javascript reactjs material-ui

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

Doing it like this i can get the gameID, but not the 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}>

I can get the value but not the gameID

我怎样才能同时获得两者?

最佳答案

因为您没有在arrow function中传递事件 ,这样写:

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

这就是事件未定义的原因。

关于javascript - 从 React MaterialUI RadioButtonGroup 获取值和 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45793615/

相关文章:

javascript - 使用取消按钮单击提交按钮后防止提交表单

javascript - 一旦单击 React,单选按钮的状态将不会保留

reactjs - import 'useAuthenticator' from aws-amplify 在 Jest 测试时输出 "TypeError: window.URL.createObjectURL is not a function"

reactjs - 单击输入字段时如何打开 mui KeyboardDatePicker 对话框

reactjs - React Material UI - 如何根据另一个值自动从自动完成中删除项目

javascript - javascript 中的 screen.width 和 screen.availwidth 区别

javascript - 将 HTML 元素的 "Style"属性转换为 JSON

javascript - 如何在 react 导航中连接 react 组件?

javascript - Vercel Postgres 批量插入,从数组动态构建 SQL 查询

javascript - 使用 CSS API 覆盖 Material UI Stepper 中的 CSS 样式