0

I'm trying to create a specific structure of data but I'm having troubles with that.

I want to do this:

  • Parts
    • u_order
    • u_familia
    • u_part
    • u_type
    • articles (i want to add an array of articles here)

First, create the array parts:

parts.push(request.query("SELECT u_order, u_familia, u_part, u_type FROM u_part (nolock) where u_order <'92'"));

Next I will iterate this array and for each part I get the articles of this part and I want to add them to parts array:

return Promise.all([Promise.all(parts)]).then(function(listOfResults)
    {
      var articles = [];
      for(var i=0; i<listOfResults[0][0].length; i++)
      {
        articles.push(request.query("SELECT ststamp, ref, design FROM st WHERE u_posic = '"+listOfResults[0][0][i].u_order+"'"));
      }

      Promise.all([Promise.all(articles)]).then(function(listOfArticles)
      {
        console.log("ARTICLES:");
        for(var j=0; j<listOfArticles[0][0].length; j++)
        {
          HERE I WANT TO ADD THE ARTICLE ARRAY TO PART
          I TRY USE SPLICE BUT DOESN'T WORK.
        }
      });

    }).catch(function(err)
    {
        console.log(err);
    });

How can I do that?

Thank you

1
  • 1
    show us how you were using splice, that might help Commented Mar 29, 2017 at 13:33

1 Answer 1

1

I would use Parts object rather than a parts array. Make an array of Parts objects containing the named keys including a key for articles:

var part = request.query("SELECT u_order, u_familia, u_part, u_type FROM u_part (nolock) where u_order <'92'");
var article = request.query("SELECT ststamp, ref, design FROM st WHERE u_posic = '"+listOfResults[0][0][i].u_order+"'");

parts.push({
  u_order: part[0],
  u_familia: part[1],
  u_part: part[2],
  u_type: part[3],
  articles: article
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.