2013-08-28 2 views
0

Я создаю цикл for с swig engine. в принципе, если у меня будет более 4 таблиц под родительским td, новый tr будет создан и продолжен ... пожалуйста, помогите! :(swig for loop node.js, express, mongodb

{% 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"} 

ответ

2

Похоже, вы не закрывая предыдущий <tr> перед созданием нового Попробуйте это:.

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