简体   繁体   English

如何在 MaterialUi React 的自动完成中将 state 放入值

[英]how to put state into value in Autocomplete in MaterialUi React

I have Autocomplete and a reset button.我有自动完成和重置按钮。 I need that pressing the button my state was reset.我需要按下按钮我的 state 被重置。 So I need to use state as a value in Autocomplete.所以我需要使用 state 作为自动完成中的值。 Can I do it?我可以做吗? (state.type="") I use class components (state.type="") 我使用 class 组件

<Autocomplete
            className={classes.root}
            id="combo-box-demo"
            options={availableTypes}
            getOptionLabel={(option) => option.title}
            onChange={this.changeType}
            renderInput={(params) => (
              <TextField
                className={classes.wrapper}
                {...params}
                label="choose any type"
              />
            )}
          />

Autocomplete does provide a clear button with the textfield itself but if you still want control this behaviour using another button, you can do something like this .自动完成确实为文本字段本身提供了一个清除按钮,但如果您仍想使用另一个按钮控制此行为,您可以执行类似操作。

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

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