Javascript 多查询nodejs-mysql

Javascript 多查询nodejs-mysql,javascript,node.js,async.js,Javascript,Node.js,Async.js,下面是运行多个查询的代码 module.exports.getAllternaryCat=function(req,res) { var output = {}; connection.query('SELECT * FROM ternary_categories',function(error,results,filelds){ if(error) throw err; async.eachSeries(results,function(data

下面是运行多个查询的代码

 module.exports.getAllternaryCat=function(req,res) {


     var output = {};

  connection.query('SELECT * FROM ternary_categories',function(error,results,filelds){
      if(error) throw err;

      async.eachSeries(results,function(data,callback){ // It will be executed one by one
              //Here it will be wait query execute. It will work like synchronous
            //  output.push(data);
                  output['ternaryCategory']= results;
              connection.query('SELECT * FROM secondary_category  where id = '+data.secondary_categoryId,function(error,results1,filelds){
                  if(error) throw err;

                //  output.push(results1)
                output['secondaryCategory']= results1;


                  callback();
              });

              connection.query('SELECT * FROM primary_category  where id = '+data.secondary_categoryId,function(error,results1,filelds){
                  if(error) throw err;

                output['PrimaryCategory']= results1;


              });


      }, function(err, results) {
           res.json({
                    status:true,
                    data:output

                })
      });


  })

}

主类别的查询没有返回结果对象,只返回ternaryCategory,secondaryCategory,而不是PrimaryCategory。新节点可以帮我解决这个问题。我试过同步落水,但我不明白

您应该在第二次查询之后调用
callback()
函数,而不是在第一次查询之后。根据报告,该查询可能甚至没有被调用

另外,您似乎正在覆盖对象属性,但我不打算深入讨论,因为我不知道您的意图,只是一个提示


我还建议您使用稍微好一点的命名约定,即不要对两个不同的查询使用results1,从长远来看,您会把自己弄糊涂。

不“进来”是什么意思,它是未定义的、空的还是根本不存在于对象中?没有错误。当我在results对象中运行应用程序时,只有ternaryCategory和secondaryCategory不是primarycategory。请重新阅读我的问题并编辑您的评论,您确实重复了您在原始问题中所说的。我不是“output”中的getting primarycategory对象对象,我的意思是作为响应…只有ternaryCategory和SecondaryCategory的查询结果出现