简体   繁体   English

React map function 没有结果

[英]React map function delivers no result

I have a simple array:我有一个简单的数组:

const plaene = [
{
"bezeichnung":"P1",
"erstelltAm":"18.07.2020"
},
{
"bezeichnung":"P2",
"erstelltAm":"18.07.2020"
 },
{
"bezeichnung":"P3",
"erstelltAm":"18.07.2020"
 }
]

So if I want to map over that array, I got no result.因此,如果我想在该阵列上 map,我没有得到任何结果。 Only when I explicitly specify the position in the map function ( plan 1 .bezeichnung ) do I get the values displayed.只有当我在 map function (计划1 .bezeichnung )中明确指定 position 时,我才能得到显示的值。 So why does the following not work?那么为什么以下不起作用?

export default function Wochen({pl}) {

return ( <div>
    {
        Object.entries(pl).map(plan =>{
            return(
                <Plaene key={plan} title={plan.bezeichnung}/> 

            );
        })
    }
    </div> )
};

在此处输入图像描述

I would try without Object.entries() as:我会尝试不Object.entries()作为:

{
     pl.map((plan, index) => {
         return(
             <Plaene key={index} title={plan.bezeichnung}/> 
         );
     })
}

Above .map() has the actual entry in plan on every iteration for your array, also index can be used as key for your component.上面的.map()在您的数组的每次迭代中都有实际的plan条目, index也可以用作组件的键。

plan - is the key. plan ——是关键。 Type pl[plan] to access the value键入pl[plan]以访问该值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM