简体   繁体   English

如何使用jade将数据从URL / API转换为node.js express中的表?

[英]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: 我已经在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: 而这在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 . 使用名为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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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