angular http post send complex objects

我是研究僧i 提交于 2019-12-07 20:16:28
const bookingItem = {
...
    'SubUnits': [
        createBooking.booking.relatedVehicles.forEach(element => {
            const units = {
                'RelationType': element.relation,
                'Weight': element.weight,
                'Year': element.year,
            };
        })
    ]
...
};

This loop doesnt fill the array in bookingItem.SubUnits. Array.forEach does not return a value. Besides that, the variable units is never used. What you can do instead is create a new array using Array.map.

'SubUnits': [
    createBooking.booking.relatedVehicles.map(element => ({
        'RelationType': element.relation,
        'Weight': element.weight,
        'Year': element.year
    }))
]

This makes an array with 1 array element from createBooking.booking.relatedVechiles. I am not sure if that's what you are going for, but it is in your OP.

Have you tried to not use JSON.stringify? Just use:

  SubUnits :unitsArray;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!