简体   繁体   中英

How do I convert data from a URL/API into a table in node.js express using jade?

I've tried this in the index.js:

var express = require('express');
var router = express.Router();
var request = require('request');

/* GET home page. */
router.get('/', function(req, res, next) {

  request('https://status.heroku.com/api/v3/issues?since=2012-04-24&limit=1',  function (error, response, body) {
     res.render('index', {
        title : 'oded',
        heroku: body}
     );

  });
});

module.exports = router;

And this in index.pug:

extends layout

block content
    h1= title
    p Welcome to #{body}

That is even before talking about the conversion to a table. Just wanted to see the data itself. Tried numerous techniques I found online but none worked for me. Appreciate your help.

Iterate your response object using field named heroku . Refer this snippet

extends layout

block content
    h1= title
    table
      tr
        th id
        th title
      each data in heroku       
        tr
          td data.id
          td data.title

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM