在React

时间:2018-12-05 04:43:15

标签: json reactjs rest

因此,这里的React相当陌生(主要是后端和devops工程师)。我需要修复一个错误,因为通常没有负责人员。

REST端点之一在将数据发送到后端时错误地格式化了日期。端点对PUT的期望数据是

 "items": [
    {
        "uuid": "abc7aba1-47ad-46d1-a3a5-d26ff55e4cf8",
        "item_id": "21626227",
        "item_description": "Test",
        "item_schedule": {
            "uuid": "37f8ca4c-6469-4bfb-822e-acfbc02e502e",
            "start_date": "2018-12-04",
            "end_date": "2018-12-06",
            "interval": 3,
            "unit": "days",
            "occurrence": 1
            "schedule_dates": [
                {
                    "uuid": "d5b73ac5-be77-40c5-b11b-45034f70f81f",
                    "planned_date": "2018-12-04",
                    "custom": true
                }
            ]
        }
    },
    {
        "uuid": "7abca4f4-1717-4136-aec6-3a37b4971c81",
        "item_id": "21626229",
        "item_description": "Test 2",
        "maintenance_plan": "31001827",
        "item_schedule": {
            "uuid": "5de45d6e-81e8-4c86-9eb2-31c71089c876",
            "start_date": null,
            "end_date": null,
            "interval": null,
            "unit": "",
            "occurrence": null,
            "schedule_dates": [
                {
                    "uuid": "da7ed2e4-053e-4f1d-80ca-2d6d258e8a08",
                    "planned_date": "2018-12-13",
                    "custom": true
                }
            ]
        }
    }

] 相反,我们获得的所有日期(即开始日期,结束日期和计划日期)都是(在这里跳过所有正确的内容。)

 "end_date": "2018-12-05T13:00:00.000Z",
 "start_date": "2018-12-03T13:00:00.000Z"
 "planned_date" : "2018-12-03T13:00:00.000Z"

为新项目创建新时间表时,旧时间表数据的格式不正确。

我试图遍历所有项目以及相关的时间表和日期,并正确格式化它们,但是似乎不起作用。

我需要在这里使用map而不是foreach吗?

const mapDispatchToProps = (dispatch, props) => ({
 save: (value, notes) => dispatch(ItemDetailAction.saveLocal(
  props.value.merge(
  Map(Object.assign(
    {
      notes: notes.setIn([0, 'created'], undefined),
      uuid: props.value.get('uuid'),
    },

    props.value.getIn(['item', 'type']) === 'P' && {
      items: props.value
        .get('items').forEach((item) => {
          console.log(item.get('item_schedule'));
          const start_date = item.get('item_schedule').get('start_date');
          if (start_date !== '') {
            const formatted_date = moment(start_date).format('YYYY-MM-DD');
           //not updating the date-format below in the same array.
           item.get('item_schedule').set('start_date',formatted_date);
           item.setIn(['item_schedule', 'start_date'],formatted_date);
           // this still prints the wrong date-format
            console.log(item.get('item_schedule').get('start_date'));
          }
        }),
    },
  )),
),
true,
{
  then: () => {
    props.onCancel();
    dispatch(actions.getItemListTable(FilterMaintenance.asParams(props.filters)));
  },
}, )), });

0 个答案:

没有答案