async editSurvey(answers) {
let answer_text;
let id;
answers.map((answer, index) => {
answer_text = answer.answer_text;
id = answer.id;
});
body: JSON.stringify({
question: {
answers_attributes: {
'0': {
answer_text: answer_text,
id: id
} }
}
})
}
这是api代码,我想要map函数,以便在每个地图上它应该转到JSON.stringify并分配值,但在我的情况下,它将转到最后一个map元素的JSON.stringify。所以请建议我任何解决方案。先感谢您。
async editSurvey(answers) {
let answer_text;
let id;
answers.map((answer, index) => {
answer_text = answer.answer_text;
id = answer.id;
return {
body: JSON.stringify({
question: {
answers_attributes: {
'0': {
answer_text: answer_text,
id: id
}
}
}
}
});
尝试做这样的事情,检查括号一次