【发布时间】:2018-12-13 18:32:52
【问题描述】:
在nodejs + express + postgres有一个小项目,用于自学。通过请求 Postgres,我获取 json 格式的数据,然后将 express 工具上的数据呈现到 ejs 模板。问题是如何将此 json 添加到 html 中的动态表中。
对数据库的请求如下所示
const pool = new pg.Pool(config);
router.get('/index', (req, res, next) => {
pool.connect(function (err, client, done) {
if (err) {
console.log("Can not connect to the DB" + err);
}
client.query('SELECT * FROM srt_final WHERE info_init @> \'{"subscriber":"999999"}\' ORDER BY id DESC LIMIT 20', function (err, result) {
done();
if (err) {
console.log(err);
res.status(400).send(err);
}
var osaka = result.rows;
res.render('index', { srt: osaka });
})
})
});
数据本身看起来像这样(大约 30 个值)。
[
{"id":11653167,"info_init":
{"date":"05.07.2018"},
....
{"Time":"10:31:17"}
},
....
{"id":11653168,"info_init":
{:},
......
{:}
}
]
【问题讨论】: