我无法让Jade正确缩进for循环中的代码:
div.container
- var cell = 0
- for(var i = 0; i < results.Items.Item.length; i++)
- if(cell == 0)
div.row
div.span3
div.cell
span #{results.Items.Item[i].ItemAttributes.Title}
- else
div.span3
div.cell
span #{results.Items.Item[i].ItemAttributes.Title}
- if(cell < 3)
- cell++;
- else
- cell = 0
else语句中的代码不在div.row中,而是在div.container下呈现,或与div.row在同一级别上。我需要else语句中的代码在div.row中呈现。我如何让Jade这样做?
我要做的是让div.row渲染,然后在每第4个div.cell(由单元格对象计算)后渲染另一个div.row
答案 0 :(得分:1)
我相信你必须这样做:
div.container
- var cell = 0
- for(var i = 0; i < results.Items.Item.length; i++)
div.row
div.span3
div.cell
span #{results.Items.Item[i].ItemAttributes.Title}
- if(cell < 3)
- cell++;
- else
div.row
- cell = 0
答案 1 :(得分:0)
使用花括号“{”和“}”
div.container
- var cell = 0
- for(var i = 0; i < results.Items.Item.length; i++){
- if(cell == 0){
div.row
div.span3
div.cell
span #{results.Items.Item[i].ItemAttributes.Title}
- }
- else{
div.span3
div.cell
span #{results.Items.Item[i].ItemAttributes.Title}
- }
- if(cell < 3)
- cell++
- else
- cell = 0
- }