我可以将包含字典对象的数组传递到异步映射中吗
can i pass array that contain dictionary object into async map
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.here 但不能得到 console.log 3.here
你能给我建议吗
使用此代码,
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);
});
}
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.here 但不能得到 console.log 3.here 你能给我建议吗
使用此代码,
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);
});
}