【问题标题】:Jade each iteration modulus for responsive Twitter BootstrapJade 响应式 Twitter Bootstrap 的每个迭代模数
【发布时间】:2013-08-24 13:15:38
【问题描述】:

对 Jade 来说非常新,整个“缩进很重要”的部分很好,但它也有缺点。

我正在尝试迭代一个对象以吐出一个响应式 Twitter Bootstrap 网格。通常,在传统的 HTML 世界中,我会使用模数通过关闭我的 </div> 来结束我当前的 row,但我不知道如何在 Jade 世界中实现这一点。

我试过这个:

  each val, index in team

      if index % 3 == 0
         div.row(style="border: solid 1px")

     .col-md-2.thumbnail
        img.img-responsive(src=val.image)
        .caption.text-center
           h4
            =val.name

但由于.col 没有正确缩进,它会引发错误。

简而言之,我想要每行三个项目,每个项目都包含在 div.row

值得注意的是,这是 new Bootstrap3 语法,但 2.3 语法中的帮助/建议非常好。

感谢任何帮助。谢谢!

【问题讨论】:

  • 您要么必须将数据结构准备为列表列表(每个列表有 3 个条目),要么使用内联原始 HTML。

标签: html twitter-bootstrap responsive-design pug twitter-bootstrap-3


【解决方案1】:

你很接近,试试这个。

each val, index in team
    if (index % 3 == 0)
        div.row(style="border: solid 1px")
            each val2, index2 in team.slice(index, index+3)
                .col-md-2.thumbnail
                    img.img-responsive(src=team[index+index2].image)
                    .caption.text-center
                        h4
                            =team[index+index2].name

【讨论】:

  • 这是答案,但您的代码有错字/错误。我必须将 if((index # 3) == 0) 修复为 if (index % 3 == 0) 才能使其正常工作。
  • 对我来说效果很好。谢谢!
猜你喜欢
  • 2012-04-17
  • 1970-01-01
  • 2012-10-12
  • 1970-01-01
  • 2013-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多