Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 为什么赢了';Jade不缩进代码吗?_Node.js_Express_Pug - Fatal编程技术网

Node.js 为什么赢了';Jade不缩进代码吗?

Node.js 为什么赢了';Jade不缩进代码吗?,node.js,express,pug,Node.js,Express,Pug,我无法让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 #{resu

我无法让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
div.container
-变量单元格=0
-对于(变量i=0;i
else语句中的代码不在div.row内部,而是在div.container下呈现,或者在与div.row相同的级别上呈现。我需要else语句中的代码在div.row内呈现。我怎样才能让杰德做这个


我试图做的是让div.row进行渲染,然后在每第四个div.cell(按cell对象计数)渲染另一个div.row

我相信您必须这样做:

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
div.container
-变量单元格=0
-对于(变量i=0;i
使用大括号“{”和“}”

div.container
-变量单元格=0
-对于(变量i=0;i
我不遵循…始终渲染div.row-目标是仅在满足条件时渲染div.row。我需要div.cell在div.row下缩进,但我不希望每次迭代都使用div.row。等等,你是说渲染后需要Jade以特定的自定义缩进输出吗?我认为这是不可能的。这不是真正的习惯-你不能在else语句中缩进是没有任何意义的,因为else语句在与else语句相同的级别上遇到其他语句之前是不会结束的。如果else语句永远不会结束,你怎么缩进呢?对不起,我误解了你的意思。检查我的编辑,这是否符合您的要求?
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
        - }