javascript - React map 函数没有结果
问题描述
我有一个简单的数组:
const plaene = [
{
"bezeichnung":"P1",
"erstelltAm":"18.07.2020"
},
{
"bezeichnung":"P2",
"erstelltAm":"18.07.2020"
},
{
"bezeichnung":"P3",
"erstelltAm":"18.07.2020"
}
]
因此,如果我想映射该数组,我没有得到任何结果。只有当我在地图函数(plan 1 .bezeichnung)中明确指定位置时,我才能得到显示的值。那么为什么以下不起作用?
export default function Wochen({pl}) {
return ( <div>
{
Object.entries(pl).map(plan =>{
return(
<Plaene key={plan} title={plan.bezeichnung}/>
);
})
}
</div> )
};
解决方案
我会尝试不Object.entries()
作为:
{
pl.map((plan, index) => {
return(
<Plaene key={index} title={plan.bezeichnung}/>
);
})
}
上面有你的数组每次迭代.map()
的实际条目,也可以用作你的组件的键。plan
index
推荐阅读
- c++ - 将任何类型的对象的函数传递给 C++ 中的另一个对象
- linux - 使用 Qt 使用 cc2564moda 在 beagleboneblack 上配置蓝牙
- java - 如何通过按后退按钮跳转到活动?
- html - 网站背景未覆盖菜单栏左右两侧
- r - R中的for循环不会为i初始化/分配正确的值
- python - 导入语句中缺少某些内容?
- reactjs - 反应条件标签名称不起作用 - 所有字母都缩小了
- angular - 运行不带星号前缀的 NgFor 指令
- web-applications - Dart One page 应用程序:没有 AngularDart 的路由
- ios - 如何在 alert.addTextfield 中放置 $ 硬币掩码?