【发布时间】:2019-03-27 12:49:59
【问题描述】:
- 在我的 post 请求中,我需要传递一个包含对象的数组。
- 当我尝试在对象中添加新属性时,它正在添加。
- 但是当我试图添加一个对象存在于数组中时,它没有添加。
我有 sportsvalues 作为数组
const sportsValues = [{ ...values }]; - 我正在尝试构建这样的东西,以便我可以传入 api
[ { "playerName": 3, "playerHeight": 1 } ] - 你能告诉我如何解决它吗?
- 在下面提供我的代码 sn-p。
export function sports(values) {
const sportsValues = [{ ...values }];
sportsValues.push(playerName:'3');
console.log("sportsValues--->", sportsValues);
// sportsValues.playerName = 3//'';
// sportsValues.playerHeight = 1//'';
console.log("after addition sportsValues--->", sportsValues);
console.log("after deletion sportsValues--->", sportsValues);
return dispatch => {
axios
.post(`${url}/sport`, sportsValues)
.then(() => {
return;
})
.catch(error => {
alert(`Error\n${error}`);
});
};
}
【问题讨论】:
标签: javascript html arrays reactjs redux