Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

javascript - How to render array of array of objects in Jade

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...