type SubOptionType = {
year: number
zest: number
}
type OptionType = Partial<SubOptionType> & {
id: number
label: string
}
const optionList = useMemo(() => {
return option.map((opt) => Object.keys(opt).filter((keyVal) => !removeItems.includes(keyVal)))
}, [option])
<Autocomplete
renderTags={(tagValue) =>
tagValue.map((tag: OptionType, index) => (
<LabelChips key={tag.id} size="small" text={tag.label} >
{optionList[index].map((el) => tag[el])}
</LabelChips>
))
}
/>
const option = [
{ id: 1, label: 'Casablanca', zest: 3000, year: 1950 },
{ id: 2, label: 'Psycho', zest: 3000, year: 1950 },
{ id: 3, label: 'The Green Mile', zest: 3000, year: 1950 },
{ id: 4, label: 'The Intouchables', zest: 3000, year: 1950 },
]
const optionList =
[
[
"zest",
"year"
],
[
"zest",
"year"
],
]
tagValue.map(tag) => tag = {
"id": 1,
"label": "Casablanca",
"zest": 3000,
"year": 1950
}
错误部分:
{optionList[index].map((el) => tag[el])}
<;==错误点!
错误名称:
在选项类型中,找不到包含该类型参数的索引签名.
如何对签名进行索引?
我希望用Typescript 来解决这个问题.