在pug模板的每个循环内创建变量 [英] Create variables inside an each loop in a pug template

查看:409
本文介绍了在pug模板的每个循环内创建变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在pug的循环内创建变量并在以后调用它们?

How can I create variables inside a loop in pug and call them later?

我从一个快速js服务器向pug模板传递了一个变量 words ,然后遍历了该变量:

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']};

然后我尝试调用变量:

  ul
     #{spelling}

我遇到此错误:SyntaxError:意外字符'#'

I have this error: SyntaxError: Unexpected character '#'

推荐答案

在每个循环内访问word时,请删除所有这些不必要的字符.

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;

这篇关于在pug模板的每个循环内创建变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆