路线:
exports.authenticate = function(req, res) {
//connection.connect();
var sql="SELECT * from users where username='"+req.body.user+"' and password='"+req.body.pass+"' LIMIT 1";
connection.query(sql, function(err, rows, fields) {
if (err) throw err;
//res.send('Your data is: ', rows);
var str="Hi, <b>"+rows[0].name+"</b> ("+rows[0].email+")";
sql="SELECT username,name from users ORDER BY name";
connection.query(sql, function(err, datarows, fields) {
if (err) throw err;
//res.send('Your data is: ', rows+' <br/> All Users are : ', datarows.length+"<a href='/'>Login</a>");
console.log(datarows);
res.render('home.jade', {title: 'Home',result:datarows});
/*---------------The above calling jade-----------------*/
});
//str+="<a href='/'>Login</a>";
//res.send(str);
//connection.end();
});
玉
extends layout
block content
//p #{result}
-var list=[ { username: 'rohankumar1524', name: 'Rohan Kumar' }]
each item, i in result
p test #{item.length}
each role,j in item
p #{role}
输出
test
rohankumar1524
Rohan Kumar
异常输出
function (parser, fieldPackets, typeCast, nestTables, connection) { var self = this; var next = function () { return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers); }; for (var i = 0; i < fieldPackets.length; i++) { var fieldPacket = fieldPackets[i]; var value; if (typeof typeCast == "function") { value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]); } else { value = (typeCast) ? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers) : ( (fieldPacket.charsetNr === Charsets.BINARY) ? parser.parseLengthCodedBuffer() : parser.parseLengthCodedString() ); } if (typeof nestTables == "string" && nestTables.length) { this[fieldPacket.table + nestTables + fieldPacket.name] = value; } else if (nestTables) { this[fieldPacket.table] = this[fieldPacket.table] || {}; this[fieldPacket.table][fieldPacket.name] = value; } else { this[fieldPacket.name] = value; } } }
此
function (field, parser, timeZone, supportBigNumbers) { switch (field.type) { case Types.TIMESTAMP: case Types.DATE: case Types.DATETIME: case Types.NEWDATE: var dateString = parser.parseLengthCodedString(); if (dateString === null) { return null; } if (timeZone != 'local') { if (field.type === Types.DATE) { dateString += ' 00:00:00 ' + timeZone; } else { dateString += timeZone; } } return new Date(dateString); case Types.TINY: case Types.SHORT: case Types.LONG: case Types.INT24: case Types.YEAR: case Types.FLOAT: case Types.DOUBLE: case Types.LONGLONG: case Types.NEWDECIMAL: var numberString = parser.parseLengthCodedString(); return (numberString === null || (field.zeroFill && numberString[0] == "0")) ? numberString : ((supportBigNumbers && Number(numberString) > IEEE_754_BINARY_64_PRECISION) ? numberString : Number(numberString)); case Types.BIT: return parser.parseLengthCodedBuffer(); case Types.STRING: case Types.VAR_STRING: case Types.TINY_BLOB: case Types.MEDIUM_BLOB: case Types.LONG_BLOB: case Types.BLOB: return (field.charsetNr === Charsets.BINARY) ? parser.parseLengthCodedBuffer() : parser.parseLengthCodedString(); case Types.GEOMETRY: return parser.parseGeometryValue(); default: return parser.parseLengthCodedString(); } }
但是当我在 jade
中使用此代码时extends layout
block content
//p #{result}
-var list=[ { username: 'rohankumar1524', name: 'Rohan Kumar' }]
each item, i in list // list in place of result
p test #{item.length}
each role,j in item
p #{role}
输出是
test
rohankumar1524
Rohan Kumar
预期
为什么发生此问题,是module
install
npm
之后的任何其他{{1}}
答案 0 :(得分:0)
试试这个:
<强>玉强>
extends layout
block content
each item in result
p item.username
p item.name