update1:
каждый раз, когда я вижу новое значение даты, мне нужно обновлять значение playerbirthDate на эту дату соответственно 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"
}