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

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

React:遍歷數組只返回第一個結果

React:遍歷數組只返回第一個結果

ITMISS 2023-05-25 15:48:36
我花了很長時間才讓它返回一個結果,但現在我只能讓這個函數返回我數組中的第一個結果。示例 JSON:(下一個函數的 JSON.stringify(mapResult) 的輸出)[  [    {      "_attributes": {        "key": "aed8d486-9557-4e53-ae9c-78bfc938c719",        "number": "1",        "type": "Video",        "title": "Stars.mov",        "shortTitle": "Stars.mov",        "state": "Completed",        "position": "119980",        "duration": "119980",        "loop": "False",        "muted": "True",        "volume": "100",        "balance": "0",        "solo": "False",        "audiobusses": "M",        "meterF1": "0",        "meterF2": "0"      },      "_text": "Stars.mov"    },    {      "_attributes": {        "key": "b9be415e-1c63-47fb-9791-72432eccd0c3",        "number": "2",        "type": "Colour",        "title": "Colour",        "shortTitle": "Colour",        "state": "Paused",        "position": "0",        "duration": "0",        "loop": "False"      },      "_text": "Colour"    },    {      "_attributes": {        "key": "23d74bb3-dbd8-410d-8b16-d05a9db4b656",        "number": "3",        "type": "Capture",        "title": "Sample Input",        "shortTitle": "Sample Input",        "state": "Running",        "position": "0",        "duration": "0",        "loop": "False",        "muted": "True",        "volume": "100",        "balance": "0",        "solo": "False",        "audiobusses": "M",        "meterF1": "0",        "meterF2": "0"      },      "_text": "Sample Input"    }  ]]
查看完整描述

1 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

您在另一個數組中有一個數組。這就是為什么您的 map 函數只返回一個元素的原因。像這樣重寫你的代碼......


const modifiedMap = mapResulst[0];

let inputMap = []

if(modifiedMap){

  inputMap = modifiedMap.map((input, i) => {

      return (

        <div key={i}>

          <h3>{input._attributes.title}</h3>

          <span>

            <Button color="danger" size="lg" block>

              {input._attributes.number}<br />

              {input._attributes.title}<br />

            State: {input._attributes.state}<br />

            Loop: {input._attributes.loop}<br />

            Type:  {input._attributes.type}<br />

            </Button>

          </span>

        </div>

      )

    })

}

return inputMap


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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