新日期

时间:2019-03-29 23:52:02

标签: javascript html json redux rect

更新1:

每次我看到新的日期值时,都需要分别用该日期更新car3 dates value---> (2) ["03/24/2019", "03/25/2019"]

 values.playerEffectiveDetails = [{
      // playerbirthDate: "2019-03-01",
      playerbirthDate: this.props.cars.car2,
      multiYearNumber: 1,
      isMultiyearRecord: "Y",
      isMemberThresholdRecord: "N"
    },
    {
      // playerbirthDate: "2019-03-01",
      playerbirthDate: this.props.cars.car2,
      multiYearNumber: 1,
      isMultiyearRecord: "Y",
      isMemberThresholdRecord: "N"
    },

    {
      isMultiyearRecord: "N",
      isMemberThresholdRecord: "Y",
      memberthresholdvalue: "2500"

    }
  ];

我需要在对象中传递多个日期。 每当我看到新的日期时,都需要使用其他对象来更新我的帖子请求中的关键playerEffectiveDetails。

现在我获得两个不同的日期值。我们将获得多个日期值。

`console.log('car3 dates value--->', dates);
    car3 dates value---> (2) ["03/24/2019", "03/25/2019"]`

对于每个日期,我需要创建一个新的其他对象并将其传递到我的帖子请求键playerEffectiveDetails中,该对象接受对象数组 values.playerEffectiveDetails = [{},{}];

我创建了一个foreach并添加了一个Object.create。但是现在我面临两个错误。

您能告诉我如何在请求中传递这个新日期吗,因为playerEffectiveDetails是一个数组,其中包含多个对象。

在下面提供我的代码段和示例请求

onSubmit(values) {
  //let playerEffectiveDetails = [];
  console.log('car3 values---->', values);

  let current = moment(new Date()).format('MM-DD-YYYY');
  console.log('current values--->', current);

  values.playerMultiYear = values.terms === 'MULTI-PERIOD' ? 'Y' : 'N';
  values.playerEvergreen = values.terms === 'EVERGREEN' ? 'Y' : 'N';

  console.log('car3 this.props.cars -->', this.props.cars);
  console.log('car1 contact type value -->', this.props.cars.car1);
  console.log('car3 this.props.cars.car2 -->', this.props.cars.car2);
  console.log("Object.keys(this.props.cars.car2).length---->", Object.keys(this.props.cars.car2).length);

  let effectivecar = [];
  effectivecar = this.props.cars.car2;
  console.log('car3 effectivecar array -->', effectivecar);
  console.log("Object.keys(effectivecar).length---->", Object.keys(effectivecar).length);

  var buz = {
    fog: 'stack',
    bog: 'use'
  };

  let outside;
  let dates = [];

  for (let name in this.props.cars.car2) {
    if (this.props.cars.car2.hasOwnProperty(name)) {
      console.log('this is fog (' +
        name + ') for sure. Value: ' + this.props.cars.car2[name]);

      //outside = this.props.cars.car2[name];
      dates.push(this.props.cars.car2[name]);
    } else {
      console.log(name); // toString or something else
    }
  }

  console.log('car3 dates value--->', dates);

  //car3 dates value---> (2) ["03/24/2019", "03/25/2019"]

  // dates.map(x => x.shift());
  // console.log("xxxxxxxxxxxx", x);


  var array1 = ['a', 'b', 'c'];

  const person = {
    // playerbirthDate: "2019-03-01",
    playerbirthDate: this.props.cars.car2,
    multiYearNumber: 1,
    isMultiyearRecord: "Y",
    isMemberThresholdRecord: "N"
  }

  let playerEffectiveDetailsArray = [];

  dates.forEach(function(element) {
    console.log(element);
    const me = Object.create(person);
    me.playerbirthDate = element;
    playerEffectiveDetailsArray.push(me.playerbirthDate);
  });

  console.log('playerEffectiveDetailsarray--->', playerEffectiveDetailsarray);
  //     let birthDateFiltered = this.props.cars.car2.filter(person => person.birthDate1 !== '' || person.birthDate1 !== undefined);

  //let birthDateFiltered = this.props.cars.car2.filter(person => person.birthDate1 !== '' || person.birthDate1 !== undefined);
  // console.log('car3 birthDateFiltered -->', birthDateFiltered);

  values.createdDate = current; //"15-01-2019";
  values.createdBy = 'jkjkjkjkjk';
  values.modifiedDate = current; //'16-01-2019';
  values.modifiedBy = 'jkjkjkjkjk';
  values.ball = '005391';
  values.playerStatus = 'PENDING';
  values.isActive = 'Y';
  values.ownerCode = 'FLB';
  values.playerType = this.props.cars.car1;
  values.playerEffectiveDetails = playerEffectiveDetailsarray;
  values.playerEffectiveDetails = [{
      // playerbirthDate: "2019-03-01",
      playerbirthDate: this.props.cars.car2,
      multiYearNumber: 1,
      isMultiyearRecord: "Y",
      isMemberThresholdRecord: "N"
    },
    {
      // playerbirthDate: "2019-03-01",
      playerbirthDate: this.props.cars.car2,
      multiYearNumber: 1,
      isMultiyearRecord: "Y",
      isMemberThresholdRecord: "N"
    },

    {
      isMultiyearRecord: "N",
      isMemberThresholdRecord: "Y",
      memberthresholdvalue: "2500"

    }
  ];

  delete values.terms;
  delete values.birthDate;
  console.log("car3 playerbirthDate values---->", values)



  axios({
      method: 'post',
      url: `${config.defaultUrl}/providerRates`,
      // data: sampleBenchMark,
      data: values,

      config: {
        headers: {
          'Content-Type': 'application/json'
        }
      }
    })

    // axios.post(`${config.defaultUrl}/providerRates/nonHosp`, values)
    .then(response => {
      console.log('third car response.data--->', response.data);
      console.log('third car data playerID--->', response.data.playerID);

      this.props.setProps({
        loading: false,
        playerID: response.data.playerID
      });
      console.log('third car data playerbirthDateID--->', response.data.playerbirthDateID);
      this.props.setcarState({ ...this.props.cars,
        car3: response.data.playerbirthDateID
      })

      this.props.onNext();
    }).catch(err => {
      alert(`onSubmit Error\n${err}`);
      this.props.setProps({
        loading: false
      });
    });

  //this.props.onNext();
}

样品申请

{

  "ball": "00539",
  "playerEvergreen": "Y",
  "playerMultiYear": "N",
  "playerType": "ANC",
  "playerStatus": "PENDING",
  "playerEffectiveDetails": [{

      "playerbirthDate": "2019-03-01",
      "multiYearNumber": 1,
      "isMultiyearRecord": "Y",
      "isMemberThresholdRecord": "N"


    },
    {

      "playerbirthDate": "2019-03-01",
      "multiYearNumber": 2,
      "isMultiyearRecord": "Y",
      "isMemberThresholdRecord": "N"


    },
    {

      "isMultiyearRecord": "N",
      "isMemberThresholdRecord": "Y",
      "memberthresholdvalue": "2500"


    }
  ],
  "isActive": "Y",
  "ownerCode": "FLB",
  "createdDate": "15-01-2019",
  "createdBy": "jkjkjkjkjk",
  "modifiedDate": "16-01-2019",
  "modifiedBy": "jkjkjkjkjk"

}

0 个答案:

没有答案