Code for searching for mysql in node.js(express)
app.get('/record', function(req,res){
sql = "select date_format(date, '%y-%m-%d') from record;"
conn.query(sql, function(err, results){
if(err){
console.log(err)
}else{
console.log(results)
res.render('record', {results:results})
}
})
})
In the console window, "date_format(date, '%y-%m-%d')": "20-03-18'
is displayed like this.
If you do this to use it in a pug,
each result in results
li=result.date_format(date, '%y-%m-%d')
result.date_format is not a function
This error occurs.
Among the results of mysql search, I think it's because the field name is included in the field name, and js recognizes it as a function, so escape to prevent it? Is there a way?
Or can we arrange the field names that are printed without brackets?
result.date_format()
If you say so, it's a function call
result['date_format()']
This is how you can use the property approach expression.
© 2024 OneMinuteCode. All rights reserved.