【发布时间】:2021-07-05 06:40:49
【问题描述】:
我正在尝试呈现从路由器 API 获得的接口列表。它被格式化为 JSON。 Pug 只渲染字符串而不是数字。
输出(在 html 中正确呈现):
em1 192.168.0.0/24
Address: 192.168.0.1
Received Packets: NaN
Sent Packets: NaN
JSON:
(em1) / 192.168.0.1":{"name":"em1","flags":"0x8943","network":"192.168.0.0/24","address":"192.168.0.1","received-packets":2524179,"received-bytes":247344321,"sent-packets":2453592,"sent-bytes":1695092680},"
哈巴狗代码:
div.container
each interface in interfaces
div.interface
h2.interface-name
| #{interface.name} #{interface.network}
p Address: #{interface.address}
p Received Packets: #{interface.received-packets}
p Sent Packets: #{interface.sent-packets}
在我的一生中,我找不到任何可以告诉我如何处理本地数字的东西。我正在使用 nodejs 并用 pug 表达。
【问题讨论】:
-
标签名称中的破折号(接收字节、发送数据包等)似乎引起了问题。如果我手动重新格式化 JSON 以删除破折号,它将呈现数字。但是 api 调用带有破折号。我真的必须格式化 json 来删除破折号吗?
标签: javascript node.js json express pug