gpt4 book ai didi

javascript - 我可以将包含字典对象的数组传递到异步映射中吗

转载 作者:行者123 更新时间:2023-11-28 05:36:45 25 4
gpt4 key购买 nike

function(req, res, next) {  
var products = [
{ id: 1, userid: 12, quntity: 12, productid: 15 },
{ id: 2, userid: 12, quntity: 8, productid: 16 }
];
console.log("------1.here-----");
// async MAP pass products array in it..
async.map(products, upProduct, function(err, result) {
console.log("------3.here-----");
if(err) {
console.log(err);
}
console.log(result);
});
function upProduct(cb) {
console.log("------2.here-----");
cb(null, products);
}
});
},

我可以在此处获得console.log 2,但在此处无法获取console.log 3。你能给我建议吗

最佳答案

使用此代码,

function(req, res, next) {
var products = JSON.parse(req.body.products);

console.log("------1.here-----");
// async MAP pass products array in it..

function upProduct(obj,cb){
cb(null,products);
}
async.map(products,upProduct,function(err, result){
console.log("------3.here-----");
if(err){
console.log(err);
}
console.log(result);
});
}

关于javascript - 我可以将包含字典对象的数组传递到异步映射中吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39303129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com