0

The asynchronous callback within for loop of node js creates issue:

for(var index in workload.elements) {
    var arr = [];
    var resourceIdentifiers = {};
    var elementinfo = {};
    var metadataModified = {};

    elementinfo = workload.elements[index];

    arr[index] = workload.elements[index].uri;

    if (workload.elements[index].parameters.imageUri) {
        arr.push(workload.elements[index].parameters.imageUri);
    }
    resourceIdentifiers = arr.join(',');

    console.log('uri' + resourceIdentifiers);

    mysql.elementlevelpricing(resourceIdentifiers, function(result){

        elementlevelpricingSummary = result;

        metadataModified = workload.elements[index].metadata;

        metadataModified.newitem = elementlevelpricingSummary;

        delete elementinfo.metadata;

        elementinfo.metadata = metadataModified;

        console.log('resultout' + JSON.stringify(elementinfo,null,2));

    });
}

In the above code , the workloads.elements is the array containing more than one value. But i get callback result for only one of the values.

2
  • 2
    This is one of those zillions :-) : stackoverflow.com/questions/750486/… Commented Jul 31, 2013 at 18:18
  • yes. i got the solution from the mentioned threads. Commented Jul 31, 2013 at 18:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.