我正在努力将回调和如何在Node中使用它们联系起来。我只想简单地找到一种产品并退还其数量。
var id = req.params.id;
let x = function findProducts(id){
// find the current product and return the quantity
Product.findById(id, (err, product) => {
if (err)
console.log("Error Selecting : %s ", err);
if (!product)
return res.render('404');
var qty = product.quantity;
return qty;
});
}
let y = function getProducts(callback) {
var results = callback();
console.log('results...', results);
}
y(x);
...need to use qty variable here