簡體   English   中英

React map function 沒有結果

[英]React map function delivers no result

我有一個簡單的數組:

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

因此,如果我想在該陣列上 map,我沒有得到任何結果。 只有當我在 map function (計划1 .bezeichnung )中明確指定 position 時,我才能得到顯示的值。 那么為什么以下不起作用?

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也可以用作組件的鍵。

plan ——是關鍵。 鍵入pl[plan]以訪問該值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM