How to render array of array of objects in Jade

偶尔善良 提交于 2019-12-13 10:06:37

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/38880613/how-to-render-array-of-array-of-objects-in-jade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!