小编kkm*_*lee的帖子

Material-UI 选择 e.target.value 未定义

我在我的 React 项目之一中使用 Material-UI 的 Select 组件。我需要按组显示下拉数据,因此我使用的是<MenuItem>环绕<ListSubheader>. 我很难获得我的MenuItems的价值。如果我的代码有任何明显错误,请告诉我。

<FormControl>
    <InputLabel>Product type</InputLabel>
    <Select
    id="product-type"
    input={<Input id="grouped-select" />}
    value={this.state.productType}
    autoWidth={true}
    style={{ width: 200 }}
    onChange={(e, child) => {
        console.log(e.target.value); // undefined!
    }}
    >
    {this.state.productList.map((p, i) => {
        const list = p[1];

        let items = list.map((e, j) => {
        return (
            <MenuItem key={j} value={e.name}>
            {e.name}
            </MenuItem>
        );
        });

        return (
        <div>
            <ListSubheader key={i}>{p[0]}</ListSubheader>
            {items}
        </div>
        );
    })}
    </Select>
</FormControl>
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

4
推荐指数
1
解决办法
2456
查看次数

标签 统计

material-ui ×1

reactjs ×1