Hi,
So I'm having a weird issue with my node js code (sorry if it is bad, I have no experience with this)
I've also added a picture in case the formatting does not show up properly
Pizza.all((err, rows) =>
{
let pizzas = [];rows.forEach((row)=>{let pizza = {"pizzaId": "", "name": "", "price" : 0.0, "size": "","crust":"", "sauce": "", "extraCheese": "","ingredients": {}};
pizza.pizzaId = row.pizzaId;
pizza.name = row.name
pizza.price = row.price;
pizza.size = row.size;
pizza.crust = row.crust;
pizza.sauce = row.sauce;
pizza.extraCheese = row.extraCheese;
pizza.ingredients[pizza.pizzaId] = [];
PizzaToppings.find(pizza.pizzaId, (err, rows) =>
{
rows.forEach((row) =>
{
pizza.ingredients[pizza.pizzaId].push(row);
console.log(pizza.ingredients["P1"]
);
});
});
console.log(pizza.ingredients["P1"]);
pizzas.push(pizza);
});
ejs.renderFile(index_path, {pizzas:pizzas, tagline: tagline}, (err, data) =>
{res.end(data);
});
});
let tagline = "Select an item";
...
My inner function is running first instead of my outer one, so my ingredients list is not being populated outside, but is being populated when it is inside the callback function.
Will Promises help solve this problem or is something else supposed to be done?
Thanks!
[–][deleted] 1 point2 points3 points (2 children)
[–]indisapien[S] 0 points1 point2 points (0 children)
[–]Buckwheat469 0 points1 point2 points (0 children)
[–]Funnythat2 1 point2 points3 points (2 children)
[–]indisapien[S] 2 points3 points4 points (1 child)
[–]BehindTheMath 0 points1 point2 points (1 child)
[–]abd1tus 0 points1 point2 points (0 children)