Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用nodejs检索sqlite数据并在浏览器中显示_Sql_Node.js_Shopping Cart - Fatal编程技术网

如何使用nodejs检索sqlite数据并在浏览器中显示

如何使用nodejs检索sqlite数据并在浏览器中显示,sql,node.js,shopping-cart,Sql,Node.js,Shopping Cart,我有一个购物车项目,它使用SQLite数据库。如何使用nodejs检索sqlite数据并在浏览器中显示它?我尝试了以下代码。我得到一个空白或空的结果。请帮帮我 <!-- language: index.js--> //index.js .get('/products', (req, res) => { var productsArr = Array(db.each('SELECT name, description, image, price FROM Product')

我有一个购物车项目,它使用SQLite数据库。如何使用nodejs检索sqlite数据并在浏览器中显示它?我尝试了以下代码。我得到一个空白或空的结果。请帮帮我

<!-- language: index.js-->
//index.js
.get('/products', (req, res) => 
{
  var productsArr = Array(db.each('SELECT name, description, image, price FROM Product'),[],(err,rows) =>
  {
    if (err)
    {
      throw err;
    }
    rows.forEach( (row) => { console.log(rows); } );
  });
  res.render('pages/products', {products: productsArr})
})

//products.ejs
<section>
  <% if (products.length){%>
    <% products.forEach(function(item) {%>
      <div class="card" style="width:18rem;">
        <img class ="card-img-top" src ="images/<%=item.image %>" alt="some `enter code here` comment">
        <div class = "card-body text-center">
          <h5><%=item.name%>&nbsp;$<%=item.price %></h5>
          <p class ="card-text"><%=item.description%></p>
          <a href="#" class "btn btn-primary" onclick="addItem(<%= item.id %>);">Add</a>
          <a href="#" class "btn btn-danger" onclick="removeItem(<%= item.id %>);">Remove</a>
        </div>
      </div>
    <%})%>
  <%}%>
</section>

//index.js
.get('/products',(req,res)=>
{
var productsArr=Array(db.each('SELECT name,description,image,price FROM Product'),[],(err,rows)=>
{
如果(错误)
{
犯错误;
}
rows.forEach((row)=>{console.log(rows);});
});
res.render('pages/products',{products:productsArr})
})
//products.ejs
“alt=“some`在此处输入代码`comment”>
$


您是
控制台。在rows数组的forEach函数中记录
行。这是打字错误吗?我正在尝试在浏览器中而不是控制台中显示每行的内容