R9102
R9102

Reputation: 727

Not able to get data after mapping array of objects in to list-reactjs

Sample 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
                }
            }
        ]
    }
}

Trying to iterate

getting data for action.payload.selectedBoardData.widgetList.map but later i am not able to get data.

please let me if there is any error.

Not able find out what is wrong in this.

code

  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 };

Upvotes: 0

Views: 35

Answers (1)

Eduardo Nishizuka
Eduardo Nishizuka

Reputation: 54

Your .map() code is fine.

It's just the way you are getting the array, try to console.log() these references to find out: action.payload.widgetList, action.payload.selectedBoardData.widgetList

Upvotes: 1

Related Questions