node.js - 如何使用 nodejs 和 express 渲染带有哈巴狗的 Neo4j 集合
问题描述
我在 Ubuntu 20.04.2 之上使用 neo4j 4.3.2 社区版
我需要在 nodejs/express 应用程序中使用 pug 显示 neo4j 密码查询的结果。
使用 neo4j 示例,使用以下代码很容易获得结果的原始列表:
router.get('/', (req, res, next) => {
const skip = int( parseInt(req.query.offset) || 0 )
const limit = int( parseInt(req.query.limit) || 25 )
const params = {
skip, limit
}
return req.neo4j.read(`
MATCH (regions:Region)
return regions
SKIP $skip LIMIT $limit
`, params)
.then(res => {
const regions = res.records.map(row => {
return new Region(
row.get('regions')
)
})
return {
regions: regions.map(n => n.toJson()),
}
})
// .then(res.render('region/regions', { "regions": res }))
.then(json => res.send(json))
.catch(e => next(e))
})
结果很简单:
{"regions":[{"name":"Lazio","uuid":"ca1c1021-92f4-412b-aa3d-6c997cba248e"},{"name":"Umbria","uuid":"4fd434a4-1eb7-4177-9a0d-d1f5aa5efdaf"},
....
{"name":"Liguria","uuid":"7612bf03-a5aa-4bda-b823-9fe361c63667"}]}
现在,我想使用以下.pug
模板显示相同的结果:
extends ../layout
block content
h1 Listing regions
table
thead
tr
th uuid
th Name
tbody
each region in regions
tr
td= region.name
td= region.uuid
所以,在我的路线文件中,我改变了行
.then(json => res.send(json))
与行
.then(res.render('region/regions', { "regions": res }))
这会导致以下错误:
TypeError: /node/kebranode/src/views/region/regions.pug:15
13|
14| tbody
> 15| each region in regions
16| tr
17| td= region.name
18| td= region.uuid
Cannot read property 'length' of undefined
知道如何摆脱它吗?
解决方案
推荐阅读
- javascript - 将html表单保存到表格中?
- python - 无法创建能够满足特定条件的 xpath
- dart - btw `BehaviorSubject` 和 `Sink` 有任何关系吗?和“流控制器”?
- scala - 需要帮助理解语法
- c - C中的嵌套if语句
- javascript - 如何使用带有 commonjs 插件的汇总部分包含 Node.js 模块
- c - 如何在循环中生成随机数,然后每 1000000 个数字将其存储在一个文件中?
- assembly - IDA 反汇编为在 Visual Studio 2017 中编译的 exe 生成与 ASM 文件完全不同的代码
- c - 在 Linux 中使用声卡。理解第一个例子(为什么不 UB?)
- json - 将 JSON 错误解析为 ArrayList