简体   繁体   English

Material-UI NativeSelect预选选项不起作用

[英]Material-UI NativeSelect preselected option not working

I've this code here: 我在这里有此代码:

<NativeSelect
classes={{
    icon: classes.icon
}}
className={classes.select}
onChange={this.onVersionChange}
    >
    {
        Object.keys(interface_versions).map(key => {
            return <option key={key} value={key}
            title={key}
            className={classes.selectOption}
            {...urlParams.get('ifversion') == key ? 'selected' : ''}
        >
            {key}
        </option>
        })};
</NativeSelect>

I've tried now to preselect an option during the creation if the key matches my URL parameter value but it's not working. 现在,如果密钥与我的URL参数值匹配,但是无法正常工作,我现在尝试在创建过程中预选择一个选项。 Can you tell me why? 你能告诉我为什么吗?

You can set the selected option by adding a value property to the NativeSelect component. 您可以通过将value属性添加到NativeSelect组件来设置所选选项。

Something like this: 像这样:

<NativeSelect 
  ....
  value={urlParams.get('ifversion')}
  ....
/>
  .....
</NativeSelect>

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

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