让我首先向您展示代码的样子
Cart.getCompleteCart((cart)=>{
let products = []; *//this Array has to be filled*
totalPrice = cart.totalPrice;
for(let prod of cart.products){
Product.getProductDetails(prod.productId, productDetails => {
products.push({
product: productDetails,
productCount: prod.productCount
});
});
}
console.log("Products are ->", products); *//this line is running before for loop!*
}
console.log() 在 for 循环完成其工作之前运行。
如何运行与 console.log() 同步的“for 循环”?
四季花海
慕尼黑5688855
相关分类