简体   繁体   English

React Material-UI Autocomplete:如何在更改另一个字段中的值时清除在自动完成字段中选择的多个值(mui 芯片)?

[英]React Material-UI Autocomplete: How to clear multiple values (mui chips) selected in a Autocomplete field on changing the value in another field?

How to clear the mui-chips in Material UI Autocomplete TextField on changing the value in another field.如何在更改另一个字段中的值时清除 Material UI Autocomplete TextField 中的 mui-chips。 In the below example, I am trying to clear subtype value whenever Type value is getting changed.在下面的示例中,每当类型值更改时,我都会尝试清除子类型值。 I am able to update the drop-down options based on value changed in the Type field.我能够根据类型字段中更改的值更新下拉选项。 But the mui chips are not getting cleared.但是 mui 芯片没有被清除。

options for Banking Type银行类型选项

In the below screenshot, I am trying to clear the options and mui-chips for the subtype field.在下面的屏幕截图中,我试图清除子类型字段的选项和 mui-chips。 Only the Options are getting updated, but mui-chips are not getting cleared.只有选项得到更新,但 mui-chips 没有得到清除。

mui chips not gettig reset, on changing Type drop-down value mui 芯片不会重置,更改类型下拉值

Issue reproducible in below codesandbox link: https://codesandbox.io/s/autocomplete-multiple-wkumx问题可在以下代码和框链接中重现: https ://codesandbox.io/s/autocomplete-multiple-wkumx

Got the answer from oliviertassinari from github.从 oliviertassinari 从 github 得到了答案。

Working solution is available at below link: https://codesandbox.io/s/autocomplete-multiple-forked-onu5n?file=/src/demo.js:0-2437以下链接提供了工作解决方案: https : //codesandbox.io/s/autocomplete-multiple-forked-onu5n?file=/src/ demo.js: 0-2437

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

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