哆啦的時(shí)光機(jī)
2021-04-06 13:10:10
我有這個(gè)數(shù)組 air_content: '', compaction_method: 1, concrete_cylinders: [ { id: '', specimen_name: 'A', mould_number: '', curing: 1, age: 7 }, { id: '', specimen_name: 'A', mould_number: '', curing: 1, age: 7 }, { id: '', specimen_name: 'A', mould_number: '', curing: 1, age: 7 } ]我試圖在發(fā)布數(shù)據(jù)時(shí)解析它們(formik將它們修改回文本,因此我需要將它們解析為int的后端)我的帖子看起來(lái)像這樣(除了嵌套對(duì)象之外,我也希望它們也解析為整數(shù))axios.post('http://localhost:8123/samples/concrete', { air_content: parseFloat(air_content), compaction_method: parseInt(compaction_method), concrete_cylinders});psuedo /我正在嘗試做的代碼的最佳嘗試如下 axios.post('http://localhost:8123/samples/concrete', { air_content: parseFloat(air_content), compaction_method: parseInt(compaction_method), concrete_cylinders: { [concrete_cylinders.id]: parseInt(concrete_cylinders.id), [concrete_cylinders.curing]: parseInt(concrete_cylinders.curing) } });謝謝您的協(xié)助
3 回答

慕神8447489
TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊
這是使用較新的傳播語(yǔ)法的版本:
const concrete_cylinders = [
{
id: '',
specimen_name: 'A',
mould_number: '',
curing: '1',
age: '7'
},
{
id: '',
specimen_name: 'A',
mould_number: '',
curing: '1',
age: '7'
},
{
id: '',
specimen_name: 'A',
mould_number: '',
curing: '1',
age: '7'
}
]
const result = concrete_cylinders.map(o => ({
...o,
...{
curing: parseInt(o.curing),
age: parseInt(o.age)
}
}));
console.log(result);
添加回答
舉報(bào)
0/150
提交
取消