循环遍历Jade中的数组

时间:2014-11-25 14:25:52

标签: node.js pug

我在jade中定义一个数组,循环遍历它以向列表中添加其他项:

        - var currencies = ['euro', 'usd', 'pound'];
        - each currency in currencies
          li
            a(
            href='#',
            ng-if='root.currency !== currency',
            ng-click='root.currency = currency')
              = currency

此处正确显示锚点,但未正确评估参数。在ng-if和ng-click语句中添加的正确语法是什么?

非常感谢

1 个答案:

答案 0 :(得分:0)

- var currencies = ['euro', 'usd', 'pound'];
- var if_flag, click_flag;
- each currency in currencies
    - if_flag = root.currency !== currency ? 'true' : 'false';
    - click_flag = root.currency === currency ? 'true' : 'false';
    li
      a(href='#', ng-if=if_flag, ng_click=click_flag
      | currency