如何从数组中添加 menuItem?

Bor*_*lis 0 reactjs material-ui

这是我的数组

const cct =cca.table.field.split(',');
console.log(cct);
Run Code Online (Sandbox Code Playgroud)
如何使用它为我的 SelectInput 添加 menuItem
  <SelectInput value={this.state.value}
            onChange={this.handleDropDownChange}            
            maxHeight={200}
            
            floatingLabelFixed={true}
            >
            {myarray}
        </SelectInput>
Run Code Online (Sandbox Code Playgroud)

我尝试这样做

    const cct = cca.table.field.split(',');
    const items= [];
    cct.forEach(element => {
      cct.push(<MenuItem key={element.Key} value={element.Key} primaryText={element.Value} />);
    });
    console.log(cct);
Run Code Online (Sandbox Code Playgroud)

但它不起作用

小智 5

我假设您正在尝试使用 Material UI SelectMenuItem组件。

以下应该有效:

render() {
  const cct = cca.table.field.split(',');

  const menuItems = cct.map(item => (
    <MenuItem key={element.Key} value={element.Key}>{item.Value}</MenuItem>
  ));

  return (
    <Select 
      value={this.state.value}
      onChange={this.handleDropDownChange}
    >
      {menuItems}
    </Select>
  );
}
Run Code Online (Sandbox Code Playgroud)