亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

映射道具時在反應中丟失鍵值對

映射道具時在反應中丟失鍵值對

阿波羅的戰車 2023-04-20 10:48:08
在向 API 發出多個請求后,我promise.all()請求并發出另一個請求,堅持上一個請求的一些屬性。這給了我:(4) [{…}, {…}, {…}, {…}]0: {product_id: "2", results: Array(4), productInfo: {…}}1: {product_id: "3", results: Array(6), productInfo: {…}}2: {product_id: "8", results: Array(9), productInfo: {…}}3: {product_id: "7", results: Array(5), productInfo: {…}}length: 4__proto__: Array(0)這productInfo: {...} 是我想要的鍵值對。在底部的這個組件中,console.log()對象出現了,但隨后它在map()? 為什么會這樣,我該如何解決?const FormatRelated = ({ recommended }) => {  //  eslint-disable-next-line no-console  console.log(recommended)  return (    <div className="recommendedThumbNailsRow">      {recommended.map(obj => {        //  eslint-disable-next-line no-console        console.log(obj);        return <DisplayRelatedImg styles={obj} />;      })}    </div>  );};
查看完整描述

1 回答

?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

Map 函數是一個 Array 函數Array Map。

如果你想遍歷對象道具,你應該使用這樣的東西:

Object.keys(recommended).map(key?=>?console.log(recommended[key]))


查看完整回答
反對 回復 2023-04-20
  • 1 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號