如何在 Jade 中渲染对象数组的数组 [英] How to render array of array of objects in Jade
本文介绍了如何在 Jade 中渲染对象数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的数组:
<预><代码>[一种: [{id":1"val":sharedVal1"},{id":2"val":sharedVal1"},]乙:[{id":3"val":sharedVal2"},{id":4"val":sharedVal2"},]C: [...]]我如何在 Jade 中渲染它?我目前的尝试看起来像
城市中的每个城市H2 ASDF城市中的每个 foo.col-md-4.row.bottomPadding.col-md-3img(src='#{foo.logo_image_url}').col-md-9.text-nowrapp.nav.hide-overflow #{foo.name}
当前没有任何渲染.如果我只是传入扁平的(未预处理的)数组并执行单个 y 中的每个 x
,它呈现得很好.
解决方案
如果你正在迭代一个对象,你需要使用 each key, value in obj
表示法:
每个键,城市中的城市H2 ASDF城市中的每一个 foo.col-md-4.row.bottomPadding.col-md-3img(src=foo.logo_image_url).col-md-9.text-nowrapp.nav.hide-overflow= foo.name
I have a an array like:
[
a: [
{
"id" : "1"
"val" : "sharedVal1"
},
{
"id" : "2"
"val" : "sharedVal1"
},
]
b: [
{
"id" : "3"
"val" : "sharedVal2"
},
{
"id" : "4"
"val" : "sharedVal2"
},
]
c: [
...
]
]
How can I render this in Jade? My current attempt looks like
each city in cities
h2 asdf
each foo in city
.col-md-4
.row.bottomPadding
.col-md-3
img(src='#{foo.logo_image_url}')
.col-md-9.text-nowrap
p.nav.hide-overflow #{foo.name}
Nothing is rendering currently. If I just pass in the flattened (un-preprocessed) array and do a single each x in y
, it renders fine.
解决方案
If you are iterating over an object, you need to use the each key, value in obj
notation:
each key, city in cities
h2 asdf
each foo in city
.col-md-4
.row.bottomPadding
.col-md-3
img(src=foo.logo_image_url)
.col-md-9.text-nowrap
p.nav.hide-overflow= foo.name
这篇关于如何在 Jade 中渲染对象数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文