簡體   English   中英

swig for loop node.js,express,mongodb

[英]swig for loop node.js, express, mongodb

我正在用swig引擎創建一個for循環。 基本上,如果我在父母的td下有超過4個表,則會創建新的tr並繼續...請幫忙! :(

{% if style and style.length %}
    <div class="products">
        <table id="products">
            <tbody>
                <tr>
{% for style in a %}
{% if loop.index0 % 4 === 0 && loop.index0 !== 0 %}
    </tr><tr>
{% endif %}
                    <td>
                    <table border="1">
                        <tbody>
                        <tr>
                        <td><a href="{{a}}"><div style="width: 175px;height: 250px" id="products"><img id="images" src="{{style.img}}" ></div></a></td></tr>
                        <tr><td id="styleno">{{style}}</td></tr>
                        </tbody>
                    </table>
                    </td>
{% endfor %}
                </tr>
            </tbody>
        </table>
{% endif %}

這是我的JSON:

{style:"1" , a:"http://", img:"http://", price: 1, desc: "ahdf"},
{style:"2" , a:"http://", img:"http://", price: 11, desc: "adsdf"},
{style:"3" , a:"http://", img:"http://", price: 13, desc: "asdaf"},
{style:"4" , a:"http://", img:"http://", price: 1, desc: "asddf"},
{style:"5" , a:"http://", img:"http://", price: 51, desc: "asssdf"},
{style:"6" , a:"http://", img:"http://", price: 71, desc: "asdf"},
{style:"7" , a:"http://", img:"http://", price: 12, desc: "asddf"}

在創建新的<tr>之前,您似乎沒有關閉之前的<tr> 嘗試這個:

{% if loop.index0 % 4 === 0 && loop.index0 !== 0 %}
    </tr><tr>
{% endif %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM