玉 - 迭代中的跨度

时间:2015-12-15 21:39:43

标签: pug

当我在字典上it时,如何添加跨度?

if the_author_posts() == "2" { 
"error you have reached your limits"
{else}
continue posting because it has not reached 2
}

我想要的货币是" c"大胆。

此代码输出:美元:0,12欧元:0,18等。

我想:美元:0,12 欧元:0,18

2 个答案:

答案 0 :(得分:0)

- each v, c in currency
    li
        strong= c
        span : #{v}

- each v, c in currency
    li #[strong= c]: #{v}

答案 1 :(得分:0)

奇怪的是冒号(:)原来是棘手的部分,但有几种方法可以做到这一点。一种是使用tag interpolation,如下所示:#[span.my-currency= c]

ul.nav.navbar-nav
  - each v, c in currency
    li #[span.my-currency= c]:#{v}

或者您可以使用JavaScript(+)连接,如下所示:

ul.nav.navbar-nav
  - each v, c in currency
    li
      span.my-currency= c
      = ":" + v

或者:

ul.nav.navbar-nav
  - each v, c in currency
    li
      span.my-currency= c
      | :
      = v

这里有一段摘录:



var template = document.getElementById('template').innerHTML;
var target = document.getElementById('target');

var currency = { Dollar: '0,12', Euro: '0,18', TL: '0.341', SEK: '0,18', MEK: '0.341', YEN: '0,18', NOK: '0.341' };
target.innerHTML = jade.compile(template)({ currency: currency });

.my-currency { font-weight: bold; }
pre { display: none; }

<script src="https://cdnjs.cloudflare.com/ajax/libs/jade/1.11.0/jade.min.js"></script>
<pre id="template">
ul.nav.navbar-nav
  - each v, c in currency
    li #[span.my-currency= c]:#{v}

ul.nav.navbar-nav
  - each v, c in currency
    li
      span.my-currency= c
      = ":" + v

ul.nav.navbar-nav
  - each v, c in currency
    li
      span.my-currency= c
      | :
      = v
</pre>
<div id="target"/>
&#13;
&#13;
&#13;