【问题标题】:How to render array of array of objects in Jade如何在 Jade 中渲染对象数组
【发布时间】:2016-12-17 06:18:54
【问题描述】:

我有一个像这样的数组:

[
  a: [
    {
      "id" : "1"
      "val" : "sharedVal1"
    },
    {
      "id" : "2"
      "val" : "sharedVal1"
    },
  ]
  b: [
    {
      "id" : "3"
      "val" : "sharedVal2"
    },
    {
      "id" : "4"
      "val" : "sharedVal2"
    },
  ]
  c: [
    ...
  ]
]

如何在 Jade 中渲染它?我目前的尝试看起来像

  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}

目前没有渲染。如果我只是传入扁平(未预处理)数组并执行单个each x in y,它会呈现良好。

【问题讨论】:

  • 发布您如何为玉提供数据。您的 gulp/grunt 配置或您如何调用 api
  • @Daniel_L 更新了 OP。
  • “如果我只是传入扁平(未预处理)数组”你是怎么做到的,发布你的代码
  • 您的“数组”无效;您在这里使用了混合对象表示法和数组结构,这可能不是您的意思。

标签: javascript node.js pug


【解决方案1】:

如果您正在迭代一个对象,您需要使用each key, value in obj 表示法:

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

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 2014-01-15
    • 2014-11-10
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    相关资源
    最近更新 更多