You are about to receive the rows value passed by the Express Router from Jade's inline JavaScript. '#{rows[1].It's accessible by the code 'id}', but I can't figure out where it's coming from. Also, why is it not accessible from the repetition? Is there any other way to approach it?
node.js code
app.get('/output', function(req, res){
var sql = 'select * from table';
conn.query(sql, function(err, rows_){
if(err){
console.log(err);
} } else {
res.render('output', {rows:rows_})}
})
});
output.jade code
html
head
body
script.
alert('#{rows[1].id}') // possible
for(var i=0; i<5; i++){
alert('#{rows[i].id}') //Not possible
};
I don't know what form Young Min's rows data comes in.I'm guessing you used id I randomly put it in a json form in an array and used it. I am attaching the image that I used, so I hope it helps you.
I searched for #{JavaScript expression}The
grammar was located in the interpolation section of the Jade document. (He doesn't say it explicitly, but just shows it as an example.))
- var msg = "not my inside voice";
p This is #{msg.toUpperCase()}
// // <p>This is NOT MY INSIDE VOICE</p>
You can also access the JavaScript variable in the iteration statement. (It can't be.) If you refer to the Jade documentation, you can try it roughly like this. (I haven't tested it.)
// This view already accepts the JS variable called rows
body
// When you enter the JS section,
script.
for (var i=0; i<5; i++) {
// I think we can just write it like this.
alert(rows[i.id + "Burnles.")
};
© 2024 OneMinuteCode. All rights reserved.