如何在 pug.js 中进行双插值?
How to do double interpolation in pug.js?
我不能像这样双重插值。有没有办法双重插值?
p #{selected} #{val.#{selectedraw}}
val 有一个动态 selected 属性,当用户在表单上按下 select 时。
所以我需要双插值。有办法吗?
The code in between #{
and }
is evaluated, escaped, and the result buffered into the output of the template being rendered.
This can be any valid Javascript expression, so you can do whatever feels good.
因此,您可以像在 JavaScript 中一样使用常规 bracket notation:
- const selected = 'foo'
- const selectedraw = 'bar'
- const val = { bar: 'ham', qux: 'spam' }
p #{selected} #{val[selectedraw]}
输出:
<p>foo ham</p>
我不能像这样双重插值。有没有办法双重插值?
p #{selected} #{val.#{selectedraw}}
val 有一个动态 selected 属性,当用户在表单上按下 select 时。
所以我需要双插值。有办法吗?
The code in between
#{
and}
is evaluated, escaped, and the result buffered into the output of the template being rendered.This can be any valid Javascript expression, so you can do whatever feels good.
因此,您可以像在 JavaScript 中一样使用常规 bracket notation:
- const selected = 'foo'
- const selectedraw = 'bar'
- const val = { bar: 'ham', qux: 'spam' }
p #{selected} #{val[selectedraw]}
输出:
<p>foo ham</p>