小编Leo*_*ter的帖子

使用哈巴狗每次循环遍历对象数组

所以我使用 NodeJs(以 pug 作为其视图引擎)。我的目的是创建一个表,其中我的 pug 代码上的 each 循环将data.json文件中的数据添加到表的行中。

首先让我向您展示我的 NodeJs 代码;我在app.js文件中有以下内容(这是我程序的主要入口点)

var express = require('express');
var pple = require('data.json');
var app = express();

app.set('view engine', 'pug');


// Get the homepage
router.get('/', (req, res, next)=>{
    res.render('index', {pple:pple});
});

app.listen(4000, ()=>{
    console.log('Listening to port 4000');
});
Run Code Online (Sandbox Code Playgroud)

其次,我的index.pug文件中有以下pug代码:

doctype html

html(lang='en')
  body
    table.table.table-striped
      tr
        th Name
        th Position
        th Address
        th Phone

      each n in pple
        tr
          td= n.name
          td= n.position
          td= n.address
          td= n.phone …
Run Code Online (Sandbox Code Playgroud)

javascript arrays json node.js pug

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrays ×1

javascript ×1

json ×1

node.js ×1

pug ×1