Bla*_*ard 9 reactjs material-ui
我有一个Autocomplete multiple select元素。当我点击十字删除某些选项时,我想获取这个值。我尝试使用ChipProps = {{onDelete: some function}}但它不起作用:(我明白了undefined,而且删除功能根本停止工作。这是我的代码
const top100Films = [
{ title: 'The Shawshank Redemption', year: 1994 },
{ title: 'The Godfather', year: 1972 },
{ title: 'The Godfather: Part II', year: 1974 },
{ title: 'The Dark Knight', year: 2008 },
{ title: '12 Angry Men', year: 1957 },
{ title: "Schindler's List", year: 1993 },
];
<Autocomplete
multiple
id="tags-standard1"
options={top100Films}
getOptionLabel={(option) => option.title}
//ChipProps = {{onDelete: (option) => {console.log(option.title)}}}
renderInput={(params) => (
<TextField
{...params}
size="small"
variant="outlined"
label="Films"
/>
)}
/>
Run Code Online (Sandbox Code Playgroud)
那么有人可以告诉我如何获取已删除选项的 ID 或值吗?
小智 8
从这个MR: https: //github.com/mui-org/material-ui/pull/19959/files开始,如果您需要整个删除的对象,您可以使用第四个参数。例如:
onChange={(event, list, reason, detail) => {
if (reason === 'remove-option') {
console.log(detail.option);
};
})
Run Code Online (Sandbox Code Playgroud)