Sunday, 16 April 2017

NodeJs item variable in array only takes the first value in a for loop

I am using expressJs to route some POST requests. From the client side I pass an object of objects and in the server I iterate over each of them with a for loop.

My problem, the variable cantidad in the loop only takes the first value instead of being refreshed into the pool.query, but before the pool.query it takes the right value.

So, the line below is ok.

console.log("cantidad before query: " + cantidad);

But the line below is bad. It has the first value.

console.log("cantidad in query: " + cantidad);

This is part of my code.

for (var key in objects) {
if (objects.hasOwnProperty(key)) { 
    ...
    console.log("cantidad before query: " + cantidad);
    pool.query(qProducto,idProducto, function (error, results, fields {
    if (error) {
    ...
} else {
    console.log("cantidad in query: " + cantidad);
    ...



via negrotico19

No comments:

Post a Comment