我在用AutoComplete API
材质 UI。有一个对象前 100 部影片其中包含电影的标题和年份。如果我搜索,我的自动完成功能可以正常工作top100Film.title
如代码所示
<Autocomplete
id="combo-box-demo"
options={top100Films}
getOptionLabel={(option) => option.title} // <--
style={{ width: 300 }}
renderInput={(params) => <TextField {...params} label="Combo box" variant="outlined" />}
/>
但如果我想搜索电影top100Films.year
然后我收到一条错误消息
<Autocomplete
id="combo-box-demo"
options={top100Films}
getOptionLabel={(option) => option.year}//<--
style={{ width: 300 }}
renderInput={(params) => <TextField {...params} label="Combo box" variant="outlined" />}
/>
Candidate.toLowerCase 不是函数。 (在“candidate.toLowerCase()”中,“candidate.toLowerCase”未定义)
我如何使用除.title
代码在Link https://codesandbox.io/s/material-demo-forked-xots5
getOptionLabel
应该返回字符串top100Films.year
返回一个数字。改变getOptionLabel
如下所示,它会正常工作:
getOptionLabel={(option) => option.year.toString()}
sandbox https://codesandbox.io/s/material-demo-forked-slebb?file=/demo.js:301-396
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)