我正在尝试在 react-native 中使用 form_data
发送数据列表,但它仅发布第一个数据,如何在 react native 中实现这一点,
我的数据,
var data = ["person_1","person_2","person_3"];
我的代码,
export function updateUsers(data,token) {
const fd = new FormData();
fd.append('first_name', data); // here i need to update all the data
return dispatch => {
axios({
method : 'patch',
url : SERVICE.url+"user/"+un+"/",
headers: {
'Authorization' : "Token "+token,
},
data : fd
})
.then(response => {
console.log("updateUser done . . .");
var data = response.data;
dispatch({
type: "UPDATE_USER",
data,
});
}).catch(error => {
console.log("got error in UPDATE_USER ", error);
});
}
}
但现在,一次只更新一个数据,所以我该如何实现。帮助我解决这个问题。
最佳答案
您应该遍历每个数据并将其附加到表单数据的 first_name 字段中。
data.forEach((item) => {
fd.append('first_name', item)
})
其余代码将相同。
关于javascript - 如何使用 react-native 为 FormData 发布数据数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46778184/