迭代FieldArray redux-form

时间:2017-08-22 18:32:44

标签: reactjs redux react-redux redux-form

有人能指出我在redux-form中迭代FieldArray值的正确方向吗?我正在制作一个表单审核页面,我想在其中显示表单的所有值。我目前有一个名为customTrips的FieldArray,如下所示:

"customTrips": [
    {
      "pick_up_date1": "2017-08-22",
      "pick_up_time1": "12:31",
      "airline1": "Delta",
      "terminal1": "12",
      "flight_Number": "213",
    },
    {
      "pick_up_time1": "12:31",
      "pick_up_date1": "2017-08-22",
      "airline1": "American Airlines",
      "terminal1": "5",
      "flight_Number": "A12",
    }
  ]

这是我用来获取所有表单值的选择器:

const selector = getFormValues('wizard');
WizardFormEighthPage = connect(state => {
  const formValues = selector(state);
    return {
      formValues
    };

})(WizardFormEighthPage);

我对如何遍历customTrips FieldArray并访问要在评论页面上显示的值感到困惑。任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:0)

我终于明白了!希望这可以帮助任何面临类似问题的人。我能够使用getFormValues选择器并使用地图访问customTrips数组。这使我能够遍历customTrips数组。

以下是获取" pick_up_date1"的示例。来自customTrips FieldArray的值:

{formValues.customTrips.map((customTrips, index) => (
   <div id="trip1_itin" className="section" key={index}>
        Address: {customTrips.pick_up_date1}
   </div>
))}