jquery - Rails 将查询 View 拆分为两个不同的 div

标签 jquery html css ruby-on-rails

我有以下 Rails 应用程序,我需要将结果作为 2 个不同的行传递给 View <div>每行有 4 个结果,2 行总共 8 个。

    </section>
        <div class="container landing-content">
            <!-- Projects Row -->
            <div class="row">
                <div class="col-md-12 text-center content-title">
                    <h3>Now trending in Kuala Lumpur</h3>
                </div>
               <% @products.each do |product| %>
                <div class="col-md-3 portfolio-item">
                    <p class="price">RM <%= product.price_cents/100 %></p>
                    <a href="<%= product_path product %>"><img src="<%= product.user.store_setting.store_image.store_img.small%>" class="img-circle user-thumb" width="52"/></a>
                    <a href="<%= product_path product %>">
                    <img class="img-responsive" src="<%= product.product_attachments.first.attachment.small.url%>" width="262" alt="">
                    </a>
                    <h4>
                        <a href="<%= product_path product %>"><%= product.name %></a>
                    </h4>
                    <a href="<%= product_path product %>">
                        <p><%= product.city%>, <%= product.country%></p>
                    </a>
                </div>
                <% end %>
    </div>

       <div class="row">

            <div class="col-md-3 portfolio-item">
</div>
</div>

    </div>
    </section>

问题是,如何将 8 个结果拆分为 2 个不同的 div?谢谢

最佳答案

我想我应该从你的 Angular 出发来阐明我的想法:

</section>
  <div class="container landing-content">
    <div class="row">
      <div class="col-md-12 text-center content-title">
         <h3>Now trending in Kuala Lumpur</h3>
      </div>
    </div>
    <% @products.each_slice(4).each do |slice| %>
      <div class="row">
        <% slice.each do |product| %>
          <div class="col-md-3 portfolio-item">
            <p class="price">RM <%= product.price_cents/100 %></p>
            <a href="<%= product_path product %>"><img src="<%= product.user.store_setting.store_image.store_img.small%>" class="img-circle user-thumb" width="52"/></a>
            <a href="<%= product_path product %>"><img class="img-responsive" src="<%= product.product_attachments.first.attachment.small.url%>" width="262" alt=""></a>
            <h4>
              <a href="<%= product_path product %>"><%= product.name %></a>
            </h4>
            <a href="<%= product_path product %>">
              <p><%= product.city%>, <%= product.country%></p>
            </a>
          </div>
        <% end %>
      </div>
   <% end %>
  </div>
</section>

关于jquery - Rails 将查询 View 拆分为两个不同的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34542173/

相关文章:

html - Internet Explorer 的投影过滤器?

jquery - $.ajax() 函数内部的返回值

javascript - 无法使用 jquery parseXML 附加 XML 节点,但可以附加字体

css - 如何在一个多行换行句子中的每一行添加水平填充?

javascript - 动态创建和编辑下拉列表内容

html - 在 HTML 中检测 Chrome 浏览器

javascript - jQuery "or"运算符不适用于 mouseleave?

带缩略图的 jQuery 画廊,单击功能只能运行一次

html 嵌套列表

jquery - 打开多个 Accordion 选项卡