简体   繁体   English

如何在 Pug 中迭代对象属性

[英]How to iterate over object properties in Pug

I've done this plenty of times but can't remember the API.我已经这样做了很多次,但不记得 API。

Amazingly I cannot put a search term into Google that will give me an answer either, so I will ask it.令人惊讶的是,我无法在 Google 中输入一个搜索词来给我答案,所以我会问它。

Given this object:鉴于此对象:

{ redeemed: false, redeemable: false, _id: 5e36319150eb6a6abd053bc3, user: 5e362dc07fc4bb348160c78f, createdAt: 2020-02-02T02:18:57.620Z, updatedAt: 2020-02-02T02:18:57.620Z, __v: 0 }

How can I iterate over all the properties in Pug.如何遍历 Pug 中的所有属性。 Something like就像是

each property in object.properties()
  p= property

Here's how to iterate over the properties of an array of objects.下面是如何迭代对象数组的属性。

h3 Payouts
each payout in payouts
    each property in Object.keys(payout)
        p Property:  #{property}
        p Value:  #{payout[property]}
        br

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM