我有一个如下的数据,我正试图从React前端发送数据到我的后台。我正在尝试转换数据并追加到表单中。但是我在
dependents
中得到了【"object Object"】。你可以看到
dependents
的数据是LIST的对象。谁能帮我把这个
dependents
数组转换成FORMADATA?
const data = {
address: "test",
bvn: "test",
dependents: [
dob: null,
email: "test@gmail.com",
photo: [File],
surname: "test"
dob: null,
email: "test@gmail.com",
photo: [File],
surname: "test"
Here is my code
const formData = new FormData()
Object.keys(data).forEach(key => {
let value = data[key]
if (value) {
if (Array.isArray(value)) {
let arr = new Array()
for (let index = 0; index < value.length; index++) {
let formData2 = new FormData();
Object.keys(value[index]).forEach(key2 => {
let value2 = value[index][key2]
formData2.append(key2, value2)
arr.push(value[index])
formData.append('dependents', JSON.stringify(arr))
} else {
formData.append(key, value)