如何提取 Pug 数组中每个第一项的值

How to extract the value of each first item in Pug array

我正在尝试使用 Pug 获取此数组中的第一项。

- val newx = {'O1_Carmine':'#E54A34', 'O2_Lipstick':'#D04735'}

each val,index in newx
    .span2(style={ background: val, color: 'black', height: '3em'} class='pad1')
        p index[0]

这呈现

<div class="span2 pad1" style="background:#E54A34;color:black;height:3em;"><p>index[0]</p></div>
<div class="span2 pad1" style="background:#D04735;color:black;height:3em;"><p>index[0]</p></div>

但我正在尝试获取;

<div class="span2 pad1" style="background:#E54A34;color:black;height:3em;"><p>O1_Carmine</p></div>
<div class="span2 pad1" style="background:#D04735;color:black;height:3em;"><p>O2_Lipstick</p></div>

有什么建议吗?

试试这个

each val,index in newx
    .span2(style={ background: val, color: 'black', height: '3em'} class='pad1')
        p= index

注意 p 之后的 =,不需要 [0](而且第一行应该是 - var,而不是 - val