将对象数组映射到list-reactjs后无法获取数据

时间:2018-05-31 15:14:59

标签: arrays json reactjs redux

示例JSON

 "data": {
    "title": "test2",
    "selectedBoardData": {
        "boardId": "1070",
        "boardTitle": "My New Board",
        "createdAt": 1526385544606,
        "modifiedAt": 1526390958854,
        "spcxId": "1070",
        "widgetList": [
            {
                "widgetId": "3b728bae-1c5a-4f48-a0c7-f9c8f0b13199",
                "widgetName": "widget 0",
                "widgetType": "venn",
                "leftTarget": "MALE",
                "rightTarget": "HHMALE",
                "leftTargetValue": 117112,
                "rightTargetValue": 160432,
                "position": {
                    "row": 0,
                    "col": 0
                }
            }
        ]
    }
}

尝试迭代

获取action.payload.selectedBoardData.widgetList.map的数据 但后来我无法获得数据。

如果有任何错误,请告诉我。

无法找出问题所在。

  const storyboardlist = action.payload.selectedBoardData.widgetList.map(widgetDataList => ({
    leftTarget: widgetDataList.leftTarget,
    rightTarget: widgetDataList.rightTarget,
    leftTargetValue: widgetDataList.leftTargetValue,
    rightTargetValue: widgetDataList.rightTargetValue,
    position: widgetDataList.position,
    //})),
  }));
  return { ...state, boardList: storyboardlist };

1 个答案:

答案 0 :(得分:1)

您的 { "success": true, "todos": [{ "_id": "5b0dc32d1f6fa0f48ca7d374", "item": "test", "completed": false, "__v": 0 }, { "_id": "5b0dc3b11f6fa0f48ca7d375", "item": "1234", "completed": false, "__v": 0 }]代码没问题。

这就是获取数组的方式,尝试使用console.log()这些引用来查找:.map()action.payload.widgetList