【发布时间】:2021-04-18 08:49:19
【问题描述】:
我有一个对象数组
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 }]
我正在使用 Material UI 的自动完成
<Autocomplete
// value={val}
options={top100Films}
getOptionLabel={option => option.title}
style={{ width: 300 }}
onChange={(event, value) => console.log(value)}
renderInput={params => (
<TextField
{...params}
label="label"
variant="outlined"
fullWidth
/>
)}
/>
它只是在 TextField 中显示值,但实际上并没有像这样设置值
<input
type="text"
value={props.value}
onChange={e => props.onChange(e.target.value)}
/>
此输入设置值。
我想在 Autofield 的 TextField 中设置值,而不仅仅是显示它。如何做呢?我已经搜索过,但找不到任何解决方案。
如果有人需要任何进一步的信息,请告诉我。
【问题讨论】:
标签: reactjs react-hooks material-table