for(i in req.body.category_id){
db.query('INSERT INTO guide_categories(category_id) values($1)', [req.body.category_id[i]],function(err,category) {
if(err) return next(err);
return console.log("success");
});
}

category_id:["3","1"]
,但数组的最后一个值是插入而休息不是。如何解决这个问题??
答案 0 :(得分:0)
更改为
for(i in req.body.category_id){
db.query('INSERT INTO guide_categories(category_id) values($1) returning *', [req.body.category_id[i]], (err,category) => {
if(err) {
console.log(err);
} else {
console.log(category);
}
};
}
并填充console.log