通过条件逻辑嵌套玉 [英] Nested jade via conditional logic

查看:93
本文介绍了通过条件逻辑嵌套玉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个检索到的json数据结果集,称为data_list.我想遍历它,并拉出它的名称字段,并将其嵌入到twitter bootstrap网格隐喻中.输出如下:

I've got a result set of json data that is retrieved that is called data_list. I want to iterate through it and pull out its name field and embed it it in a twitter bootstrap grid metaphor. The output of this would look something like the following:

<div class="row">
   <div class="span4">Name 1</div>
   <div class="span4">Name 2</div>
   <div class="span4">Name 3</div>
</div>
<div class="row">
   <div class="span4">Name 4</div>
   <div class="span4">Name 5</div>
   <div class="span4">Name 6</div>
</div>

问题是我不确定如何在Jade中完成此操作.我知道如何使用

The problem is I'm not sure how to accomplish this in Jade. I know how to iterate through my data with

- for (var key in data_list)
    div.span4
        p= data_list[key].name

我不知道该怎么做,就是为每三个数据记录注入一个数据,并使其包围这三个记录.我知道如何通过

What I don't know how to do is to inject the in for every three records of data and have it surround those three records. I know how to capture every three records via

- if ((key % 3) == 0)
    .row

但是我只能让它输出a,但不能让它包围其他行.任何建议都将受到欢迎.

but I can only get it to output a but I can't get it to surround the other rows. Any suggestions would be greatly welcome.

推荐答案

昨天我使用引导程序遇到了同样的问题.

I was facing the same problem yesterday using bootstrap.

我这样解决了:

each element, i in dataset
  if i % 3 == 0
    div.row
      each elementInRow, j in dataset.slice(i, i+3)
        div.span4
          ...cell code...

希望有帮助!

这篇关于通过条件逻辑嵌套玉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆