PugJS 没有从 json 中插入数字
PugJS not interpolating numbers from json
我正在尝试呈现从路由器 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 并用哈巴狗表达。
好的,回答我自己的问题。标识符名称中的破折号似乎不起作用。为了访问该项目,在它周围加上方括号和单引号。所以以下工作:
div.interface
h2.interface-name
| #{interface.name} #{interface.network}
p Address: #{interface.address}
p Received Packets:
|#{interface['received-packets']}
p Received Bytes: #{interface['received-bytes']}
p Sent Packets: #{interface['sent-packets']}
来自:Unable to access JSON property with "-" dash
我正在尝试呈现从路由器 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 并用哈巴狗表达。
好的,回答我自己的问题。标识符名称中的破折号似乎不起作用。为了访问该项目,在它周围加上方括号和单引号。所以以下工作:
div.interface
h2.interface-name
| #{interface.name} #{interface.network}
p Address: #{interface.address}
p Received Packets:
|#{interface['received-packets']}
p Received Bytes: #{interface['received-bytes']}
p Sent Packets: #{interface['sent-packets']}
来自:Unable to access JSON property with "-" dash