[英]Selecting multiple columns and send to jade
我正在使用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);
});
}
當用戶登錄時,我調用該函數(var x是用戶標識):
getRobots("robot", x, function(err, data) {
if (err) {
console.log("ERROR : ", err);
} else {
console.log(data);
res.render('logged_in', {
data: data
});
}
});
回調返回我這個:
[ 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 } ]
我的問題是,如何分離和檢索所有列數據,並發送到我的玉器布局中?
我想做這樣的事情:
<ul>
<li>Robot 1 | Id 1</li>
<li>Robot 2 | Id 2</li>
...
謝謝。
在您的哈巴狗模板中,您需要創建一個表,其中的每個語句都位於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.