如何将Material UI自动完成多项选择限制为一组 [英] How to limit Material UI Autocomplete multiple selections to one group
问题描述
我想将Material UI自动完成组件中的多个选择限制为同一组中的选项.
I would like to limit multiple selections within the Material UI Autocomplete component to options within the same group.
有关未设置解决方案的问题的设置,请参见链接的沙箱. https://codesandbox.io/s/material-demo-7g4ed?file =/demo.js
See linked sandbox for a setup of the problem without an implemented solution. https://codesandbox.io/s/material-demo-7g4ed?file=/demo.js
例如,在上方的沙箱中,用户只能选择Apple或Amazon产品,而不能同时选择两者.
So, for example in the sandbox above the user should only be able to select Apple or Amazon products, not both.
任何帮助将不胜感激!
推荐答案
假设您要将选择限制为3个,在代码中更新这两行
Suppose you would like to limit selections to 3, update those two lines in your code
freeSolo = {tags.length>3个?false:true}
getOptionDisabled = {(options)=>(tags.length> 3?true:false)}
这篇关于如何将Material UI自动完成多项选择限制为一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!