从称为DB.ALL的退货

时间:2019-03-25 13:40:47

标签: javascript angular typescript sqlite

试图从DB all函数获取行值。无法将其移出DB.All函数或将其拉离箭头。我获得的控制台日志将返回我想要的输出,但是我希望将其拉出,以便可以使用JSON值。

有什么想法吗?

handler: (request, h) => {
        let sql = `SELECT TRIAL_ID as indexTrial, URL as urlImage FROM TRIAL`;
        var test ='hi';


            db.all(sql, (err, rows) => {
                if (err) {
                    throw err;
                }
                test= JSON.stringify(rows);
                console.log(test);
                test =rows;
                //return rows;
            });


        return test;

    }

1 个答案:

答案 0 :(得分:0)

需要一个承诺,因为它会很快获得价值

<html>
<head>
  <script type = "text/javascript" src = "action.js" ></script>
  <link rel="stylesheet" href='to-do_style.css'>
  <link href="https://fonts.googleapis.com/css?family=Raleway" 
  rel="stylesheet">
</head>
<body>
  <div id="div1" class="left">
    <h1>Tasks</h1>
    Add tasks by typing into right panel and <br>press enter.
  </div>
  <div id="div2" class="right">
    I need to...<br>
    <textarea id='task' rows="15" cols="76"onkeypress="detect(event)">    
    </textarea>
  </div>
</body>
</html>