简体   繁体   English

自动完成 MaterialUI - 如何在分组自动完成中设置默认值

[英]Autocomplete MaterialUI - How can I set a default value in Grouped autocomplete

I am using Autocomplete grouped component?我正在使用自动完成分组组件? I want that a default value already selected when component loads or refresh.我希望在组件加载或刷新时已经选择了默认值。

Code is below code代码在代码下方

<Autocomplete
    id="grouped-demo"
    className={'input-dropdown'}
    options={options.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter))}
    groupBy={(option) => option.firstLetter}
    getOptionLabel={(option) => option.title}
    onChange={this.linkDropdownChange}
    renderInput={(params) => <TextField {...params} label="grouped Collection" variant="outlined" />}
/>

As per the documentation, you got two options根据文档,您有两个选择

Controllable states The component has two states that can be controlled:可控状态 组件有两种可以控制的状态:

the "value" state with the value/onChange props combination. “值” state 与 value/onChange 道具组合。 This state represents the value selected by the user, for instance when pressing Enter.这个 state 代表用户选择的值,例如按下 Enter 时。 the "input value" state with the inputValue/onInputChange props combination. “输入值” state 与 inputValue/onInputChange 道具组合。 This state represents the value displayed in the textbox.这个 state 代表文本框中显示的值。

Done!!!!!完毕!!!!!

Autocomplete grouped component uses defaultValue as object not a string自动完成分组组件使用defaultValue作为object而不是string

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

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