问题
How can I create variables inside a loop in pug and call them later?
I passed a variable words from an express js server to a pug template and I looped through the variable:
each word, index in words
- var spelling = #{word['orth']};
- var pronunciation = #{word['pron']};
Then I tried to call the variables:
ul
#{spelling}
I have this error: SyntaxError: Unexpected character '#'
回答1:
Remove all these unnecessary characters when access word
inside the each loop.
each word, index in words
- var spelling = word.orth;
- var pronunciation = word.pron;
来源:https://stackoverflow.com/questions/47604403/create-variables-inside-an-each-loop-in-a-pug-template