我正在尝试实现物料UI自动完成,要求以表格格式显示建议,并带有指定列名的标题。请查看下图以了解要求:
我试过下面的代码:
<Autocomplete
id="free-solo-demo"
freeSolo
disableClearable
options={top100Films}
renderInput={(params) => (
<TextField {...params} label="Combo box" variant="outlined" />
)}
getOptionLabel={(option) => option.title}
renderOption={(option) => (
<React.Fragment>
<table>
<thead>
<tr>
<th style={{ width: "400" }}>Name</th>
<th style={{ width: "60" }}>Year</th>
</tr>
</thead>
<tbody>
<tr>
<td>{option.title}</td>
<td>{option.year}</td>
</tr>
</tbody>
</table>
</React.Fragment>
)}
/>
但是它在为数组中的每个对象运行时为每个renderOption
创建不同的表,我在这里面临的主要问题是不能使用renderOption
只生成表体,然后将其 Package 在表中。
麻烦你帮我处理一下,先谢了。
工作沙盒URL
2条答案
按热度按时间jaql4c8m1#
output click here
mw3dktmi2#
是的,你可以使用自动完成中的renderOption来完成。在我的例子中,我用了不同的方法来完成格式化。但是我认为你可以不费吹灰之力地将它转换成一个表格。
下面是代码