【发布时间】:2020-07-17 23:29:26
【问题描述】:
如何在自动完成表单的标签中同时显示标题和年份?
这是标准的 Material UI 演示。当我尝试使用数组在表单标签中同时显示标题和年份时,我收到关于小写结果的错误。我认为这是因为该值不再是字符串 - 但我不知道如何解决这个问题。
<Autocomplete
multiple
id="checkboxes-tags-demo"
options={top100Films}
disableCloseOnSelect
getOptionLabel={(option) => [{option.title}, {option.year}]} // - this doesn't work
renderOption={(option, { selected }) => (
<React.Fragment>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
//[{option.title}, {option.year}] - this doesn't work
</React.Fragment>
)}
style={{ width: 500 }}
renderInput={(params) => (
<TextField {...params} variant="outlined" label="Checkboxes" placeholder="Favorites" />
)}
/>
);
}
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ title: 'The Shawshank Redemption', year: 1994 },
{ title: 'The Godfather', year: 1972 },
【问题讨论】:
标签: reactjs material-ui