示例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 };
答案 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