如何精美地显示从表格中的postgres(节点js)获得的数据?

时间:2018-06-07 08:28:17

标签: javascript json node.js postgresql ejs

在postgres中提出请求后

 `
        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 cdr_final WHERE info_init @> \'{"subscriber":"9999999999"}\' ORDER BY id DESC LIMIT 20', function (err, result) {
                done();
                if (err) {
                    console.log(err);
                    res.status(400).send(err);
                }

                res.render('index', { cdr: result });
           })

       })
    });`
 I get the data in jsonb format

{"command":"SELECT","rowCount":18,"oid":null,
"rows":[{
        {"id":754210,"info_init":{"Hour":"10","Time":"10:34:27",...,"subscriber":"99999999999",},"info_final":{"Shift":115,"OutCome":0,...,},"state":1},
        {"id":754210",info_init":{"Hour":"10","Time":"10:34:27", ... "subscriber":"99999999999",},"info_final":{"Shift":115,"OutCome":0, ..."WorkMode":48,},"state":1}
    }]
    }

,我需要 将此数据放在index.ejs的表中。因为不久前才开始认识 节点js如何做但尚未提前表示 谢谢大家的帮助。

0 个答案:

没有答案