小编Jas*_*ugh的帖子

Material UI 中的 getOptionLabel 问题

我有一个这样的常数:

const Reference = [
  { label: "RF-100", year: "Test" },
  { label: "RF-200", year: "Test2" },
  { label: "RF-300", year: "Test3" },
];
Run Code Online (Sandbox Code Playgroud)

我在 MUI 中有自动完成功能,如下所示:

export const Auto: React.FC = () => {
  return (
    <Autocomplete
      id="Combox-demo"
      options={Reference}
      //getOptionLabel={(option) => `${option.name}`}
      style={{ width: 300 }}
      renderInput={(params) => <TextField {...params} label="Combo box" variant="outlined" prefix="RF" />}
    />
  );
};
Run Code Online (Sandbox Code Playgroud)

我试图让我的 getOptionLabel 显示标签 - 年,所以它将是 RF-100 - 测试(作为示例)

当我使用

getOptionLabel={(option) => `${option.label}`}
Run Code Online (Sandbox Code Playgroud)

我明白了

类型“string | ”上不存在属性“label” { 标签:字符串;年:字符串;}'。类型“string”上不存在属性“label”

大家有什么想法吗?

typescript reactjs material-ui

5
推荐指数
1
解决办法
1880
查看次数

标签 统计

material-ui ×1

reactjs ×1

typescript ×1