U
U
urajo2019-11-25 13:08:53
Node.js
urajo, 2019-11-25 13:08:53

How to sequentially execute a query?

var menuOtd = [];

  pnd.findOne({where:{id: request.body.dataPnd}})
    .then(pnds=>{
      
      if(!pnds) return;
      pnds.getOtds().then(otds=>{
        for(ot of otds){
          if(ot.pndOtd.sub == "true"){

          }else{
            menuOtd.push(ot.name);
          };
        };			
      })
      .finally(console.log(menuOtd));
    })

Why does the final block output an empty array? In theory, it should be executed after .then, which means it should not be empty, the result is pushed into it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question