在while循环nodejs未发生时运行查询

时间:2018-06-03 15:23:48

标签: node.js

嗨我正在运行while循环,但是在console.log("In while loop")之后,while循环没有在第二行中运行块

这是整个部分

router.post("/", function(req,res,next){
  router.use(bodyParser.json());
  let tag_id = generate_tag();
  let tag_id_correct = false;
  while(tag_id_correct != true){
    console.log("in while loop");
    res.locals.connection.query("SELECT Tag_ID from trakk_items WHERE Tag_ID = '" + tag_id +"'", function (error, results, fields){
      console.log("WE ARE IN");
      if (error) {
        res.send(JSON.stringify({
          "status": 500,
          "error": error,
          "response": null
        }));
      }
      else{
        tag_id_correct = true;
        console.log(tag_id_correct);
      }
      console.log(results);
      res.send(JSON.stringify({
        "response" : results
      }));
    });
  }
  console.log("unique tagid created");

});

module.exports = router;

任何建议

由于

0 个答案:

没有答案