简体   繁体   English

选择多列并发送到玉

[英]Selecting multiple columns and send to jade

I'm building an web application using Node.js, and I'm getting data from my Mysql database using the following function: 我正在使用Node.js构建Web应用程序,并且正在使用以下功能从Mysql数据库获取数据:

function getRobots(robotname, ownerid, callback) {
    connection.query('SELECT * FROM robots WHERE robot_owner_id = ?', ownerid, function(err, rows, fields) {
        if (err) callback(err, null);
        else 
        callback(null, rows);
    });
}

And when the user Logs in I call the function (var x is the user id): 当用户登录时,我调用该函数(var x是用户标识):

        getRobots("robot", x, function(err, data) {
            if (err) {

            console.log("ERROR : ", err);
            } else {
            console.log(data);
            res.render('logged_in', {
            data: data
            });
            }
        });

The callback returns me this: 回调返回我这个:

[ RowDataPacket {
    robot_id: 1,
    robot_name: 'one',
    robot_status: 1,
    robot_owner_id: 35 },
  RowDataPacket {
    robot_id: 2,
    robot_name: 'ASAS',
    robot_status: 1,
    robot_owner_id: 35 } ]

And my question is, how can I separate and retrieve all the columns data, and send to my jade layout? 我的问题是,如何分离和检索所有列数据,并发送到我的玉器布局中?

I would like to do something like this: 我想做这样的事情:

<ul>
<li>Robot 1 | Id 1</li>
<li>Robot 2 | Id 2</li>
...

Thank you. 谢谢。

In your pug template you need to create a table with an each statement right below the tbody: 在您的哈巴狗模板中,您需要创建一个表,其中的每个语句都位于tbody的正下方:

table
  thead
    tr
      th ID
      th Name
      th Status
      th OwnerID
  tbody
    each robot in data
      tr
        td= robot.id
        td= robot.name
        td= robot.status
        td= robot.owner_id

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

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