javascript - Material-UI 自动完成警告:使用 `getOptionSelected` 属性自定义相等测试
问题描述
我正在使用带有动态创建选项的自动完成文本字段多个值。问题是我总是收到错误“没有任何选项与["prova1","prova2","prova3"]
您可以使用getOptionSelected
道具来自定义相等测试”。我错过了什么?
这是代码:
const top100Films = [ 'prova1','prova2','prova3' ];
const [tags, setTags] = useState([top100Films[0], top100Films[1]]);
<Autocomplete
multiple
id="tags-outlined"
noOptionsText={'Nessuna opzione'}
options={top100Films}
onChange={(event, value) => setTags(value)}
getOptionSelected={(option, value) => option === value.value}
getOptionLabel={(option) => option}
defaultValue={[top100Films[0], top100Films[1]]}
filterOptions={(options, params) => {
const opt = options.filter(r => tags.filter(x => x === r ).length === 0)
const filtered = filter(opt, params);
// Suggest the creation of a new value
if (params.inputValue !== '' && tags.filter(x => x === params.inputValue).length === 0) {
filtered.push(params.inputValue)
}
return filtered
}}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
label="Tag"
placeholder="Inserisci tag"
/>
)}
/>
解决方案
https://next.material-ui.com/guides/migration-v4/
在 MUI 版本 5 中,getOptionSelected 已重命名为 isOptionEqualToValue
推荐阅读
- java - 当枚举属性由于新继承而始终具有相同的值时,我应该保留它吗?
- python - 我在选择随机颜色时试图排除黑色
- python - ValueError:输入包含的值对于 dtype('float32') 来说太大了
- javascript - vue - 如何在 Slick-carousel 中的弹性项目之间制作间隙
- php - sendinblue php,如何添加附件
- c - 给定的代码在函数调用中如何工作?
- react-native - React 原生声音使用户音乐静音(Spotify、deezer 等)
- windows - 我如何从另一台电脑连接到我的本地主机服务器?(在同一个网络)
- laravel - 在 laravel 中配置电子邮件传递?
- google-chrome - 在 Chrome Devtools Inspector 中禁用“长度创作工具”(css 单位选择器)