简体   繁体   English

将数组从node.js传递到HTML页面中的另一个数组

[英]Passing an array from node.js to another array in an HTML page

app.post('/reserveWorkspace', function(req, res) {

        connection.query( 'SELECT DeskName FROM desks WHERE stat = ?',["Booked"], function(err,     rows){
        if(err)
        {
            throw err;
        }
        else
        {
          try
           {

              res.render('workspaces.html',{myArray: rows.DeskName});
              for(i=0;i<rows.length;i++)
              {        
                console.log(rows[i].DeskName);
              }}
          catch (e)
           {
            console.log(e);
           }
        }
});

I have the above node.js code, what i want to accomplish is that i want to pass all the selected rows from my DB table to the "myArray" and pass the array to another javascript array in an HTML page which is workspaces.html . 我有上面的node.js代码,我想完成的事情是我想将所有选定的行从数据库表传递到“ myArray”,并将该数组传递给HTML页面中的另一个JavaScript数组,即工作区。 。 i can successfully display them on the console, but i cant successfully pass them to the html page..... Any suggestions? 我可以成功地在控制台上显示它们,但是我不能成功地将它们传递给html页面.....有什么建议吗?

HERE IS THE HTML CODE: 这是HTML代码:

 <script type="text/javascript">
   function myFunction(){
      var bookedSeatss =  "<%= myArray%>";
      document.getElementById("test2").value = bookedSeatss[0];
    }
 </script>

尝试对它们进行分类:

res.render('workspaces.html',{myArray: JSON.stringify(rows.DeskName)});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM