我有一个const,应该在浏览器中显示为一个表,使用方法MAP。问题在下面(表中未显示汽车)。有人能帮忙吗?
const topCars = [
{manufacturer:'Fiat', model:'m5'},
{manufacturer:'Nissan', model:'e6'},
{manufacturer:'Lexus', model:'r'}
]
我的代码:
export type NewComponentType = {
cars: CarsType[]
}
export type CarsType = {
manufacturer: string
model: string
}
export const NewComponents = (props: NewComponentType) => {
return (
<>
{props.cars.map((objectFromCarsTypeArray, index) => {
return (
<table>
<thead key={index}>
</thead>
<tr>
<td>{objectFromCarsTypeArray.manufacturer}</td>
<td>{objectFromCarsTypeArray.model}</td>
</tr>
</table>
)
})}
</>
);
};
以及它在浏览器中的显示方式:
Fiat m5
Nissan e6
Lexus r
尝试:重命名表标记-没有发生任何事情
1条答案
按热度按时间hvvq6cgz1#
1.错误显示您需要
<tbody>
元素来 Package 行。1.此时,您正在为每个对象生成一个表。您需要将
<table>
、<thead>
和<tbody>
移动到map
之外。1.不要使用
map
的索引来生成键,而是向数据集中的对象添加id
属性并使用它。